Opened 8 months ago
Last modified 3 weeks ago
#35308 assigned Cleanup/optimization
FileNotFoundError escapes from run_formatters() — at Version 1
Reported by: | Jacob Walls | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | black, code formatting |
Cc: | Jeetu Singh | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
A couple coworkers of mine have now run into this issue described on the Django forum.
In essence, it's not safe to assume that just because shutil.which("black")
returns a path that subprocess.run()
can execute that path.
Some complications with shutil.which(..., path=None)
:
- Reads a path variable from one or two fallbacks (either os.environ() or os.defpath)
- Behavior is different on Windows
- Behavior is different on Windows with Python 3.12.0
- Behavior is different on Windows with Python 3.12.1
My impression of the feature was that it was aiming at a frictionless experience -- format if you have a working black install, don't if you don't.
Suggesting we should catch FileNotFoundError
(at least) and at most log out an explanation why the file wasn't formatted. Users who only have a copy of black in abandoned environments are unlikely to care about their files not being formatted. :-)