You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running black with --stdin-filename, the pyproject.toml configuration isn't respected if running black from a parent directory relative to the location of pyproject.toml.
To Reproduce
Suppose you have a directory structure as follows:
where main.py has just one print statement such as print("This line is too long") and pyproject.toml has this black config
[tool.black]
line-length = 20
If your current working directory is the parent of backends and you run black by passing the path to main.py it reformats the file as expected
❯ black -v backends/src/app/main.py
Identified `/Users/rrodrigues/Downloads/backends` as project root containing a pyproject.toml.
Sources to be formatted: "src/app/main.py"
Using configuration from project root.
line_length: 20
reformatted backends/src/app/main.py
All done! ✨ 🍰 ✨
1 file reformatted.
If you use stdin it reports the file was reformatted but the output shows it wasn't
❯ cat backends/src/app/main.py | black -v --stdin-filename backends/src/app/main.py -
Identified `/Users/rrodrigues/Downloads/backends` as project root containing a pyproject.toml.
Sources to be formatted: "-"
print("This line is too long")
reformatted backends/src/app/main.py
All done! ✨ 🍰 ✨
1 file reformatted.
Expected behavior
If your current working directory is backends, using stdin works as expected as shown below. The expected behavior is that going up one directory shouldn't change black's output when using stdin, as is the case if not using stdin.
cat src/app/main.py | black -v --stdin-filename src/app/main.py -
Identified `/Users/rrodrigues/Downloads/backends` as project root containing a pyproject.toml.
Sources to be formatted: "-"
Using configuration from project root.
line_length: 20
print(
"This line is too long"
)
reformatted src/app/main.py
All done! ✨ 🍰 ✨
1 file reformatted.
Describe the bug
When running
black
with--stdin-filename
, thepyproject.toml
configuration isn't respected if runningblack
from a parent directory relative to the location ofpyproject.toml
.To Reproduce
Suppose you have a directory structure as follows:
where
main.py
has just oneprint
statement such asprint("This line is too long")
andpyproject.toml
has thisblack
configIf your current working directory is the parent of
backends
and you run black by passing the path tomain.py
it reformats the file as expectedIf you use
stdin
it reports the file was reformatted but the output shows it wasn'tExpected behavior
If your current working directory is
backends
, usingstdin
works as expected as shown below. The expected behavior is that going up one directory shouldn't change black's output when usingstdin
, as is the case if not usingstdin
.Environment
Additional context
Issue originally reported at the Black VSCode extension repo.
The text was updated successfully, but these errors were encountered: