Opened 12 months ago

Last modified 3 months ago

#35308 closed Cleanup/optimization

FileNotFoundError escapes from run_formatters() — at Initial Version

Reported by: Jacob Walls Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: black, code formatting
Cc: Jeetu Singh Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:18597 merged

Description

Two members of my team 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. :-)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top