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
The only file I want black to pay attention to is z.py.
Then I run black --exclude='large_ignored_dir/' --check -v . which shows me:
Identified `/` as project root containing a file system root.
Found input source directory: "[...]/my-project"
[...]/my-project/large_ignored_dir ignored: matches the --exclude regular expression
would reformat [...]/my-project/z.py
Oh no! 💥 💔 💥
1 file would be reformatted.
That seems to be the correct behavior.
But black is supposed to automatically ignore directories listed in .gitignore (docs). So if I add a .gitignore file containing this line:
large_ignored_dir/
Then I should be able to run black --check -v . and see the same result as above. But instead I see:
Identified `/` as project root containing a file system root.
Found input source directory: "[...]/my-project"
[...]/my-project/large_ignored_dir/inner ignored: matches a .gitignore file content
[...]/my-project/large_ignored_dir/a.py ignored: matches a .gitignore file content
[...]/my-project/large_ignored_dir/inner2 ignored: matches a .gitignore file content
[...]/my-project/large_ignored_dir/inner3 ignored: matches a .gitignore file content
would reformat [...]/my-project/z.py
Oh no! 💥 💔 💥
1 file would be reformatted.
Even though the final result is the same (only z.py is reformatted), in this second case black is wasting time checking files that it could have skipped. Instead of ignoring all of large_ignored_dir it is descending one level inside it and then deciding to skip every file and subdirectory.
This has performance consequences with directories like node_modules and __pycache__.
Environment
Black's version: 24.4.2
OS and Python version: macOS Sonoma 14.5, M1 chip, Python 3.12
The text was updated successfully, but these errors were encountered:
Interestingly, if the content of .gitignore is set to large_ignored_dir without a trailing slash, it works as expected:
Found input source directory: "[...]\my-project"
[...]\my-project\large_ignored_dir ignored: matches a .gitignore file content
[...]\my-project\z.py already well formatted, good job.
All done! ✨ 🍰 ✨
1 file would be left unchanged.
So maybe we should add a trailing slash to relative_path in _path_is_ignored() if the path is a directory?
Say I have this file structure:
The only file I want black to pay attention to is
z.py
.Then I run
black --exclude='large_ignored_dir/' --check -v .
which shows me:That seems to be the correct behavior.
But black is supposed to automatically ignore directories listed in
.gitignore
(docs). So if I add a.gitignore
file containing this line:Then I should be able to run
black --check -v .
and see the same result as above. But instead I see:Even though the final result is the same (only
z.py
is reformatted), in this second case black is wasting time checking files that it could have skipped. Instead of ignoring all oflarge_ignored_dir
it is descending one level inside it and then deciding to skip every file and subdirectory.This has performance consequences with directories like
node_modules
and__pycache__
.Environment
The text was updated successfully, but these errors were encountered: