Skip to content

Commit

Permalink
Fix misdetection of project root with --stdin-filename
Browse files Browse the repository at this point in the history
There are a number of places this behaviour could be patched, for
instance, it's quite tempting to patch it in `get_sources`. However
I believe we generally have the invariant that project root contains all
files we want to format, in which case it seems prudent to keep that
invariant.

Fixes psf#3207
  • Loading branch information
hauntsaninja committed Aug 10, 2022
1 parent 507234c commit 6e4b7e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,13 @@ def main( # noqa: C901
out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.")
ctx.exit(1)

root, method = find_project_root(src) if code is None else (None, None)
if stdin_filename is not None:
src_with_stdin_filename = tuple(stdin_filename if s == "-" else s for s in src)
else:
src_with_stdin_filename = src
root, method = (
find_project_root(src_with_stdin_filename) if code is None else (None, None)
)
ctx.obj["root"] = root

if verbose:
Expand Down

0 comments on commit 6e4b7e5

Please sign in to comment.