Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed semantics for matching files in project root with --include #3975

Closed
sth opened this issue Oct 24, 2023 · 1 comment
Closed

Changed semantics for matching files in project root with --include #3975

sth opened this issue Oct 24, 2023 · 1 comment
Labels
T: bug Something isn't working

Comments

@sth
Copy link
Contributor

sth commented Oct 24, 2023

Describe the bug

If I have as file named somefile in the root of the project and I want to include it with --include, traditionally the appropriate regex would contain a leading slash:

black --include '^/somefile$' ...

In #3846 this changed, now the leading slash prevents the file from being matched. Instead --include '^somefile$' is required.
The related exclude regexes still need the leading slash.

The cause are the path processing changes in #3846. Slashes are only added to root_relative_path when checking excludes and are now missing from normalized_path, which is later used to check includes.

To Reproduce

$ python3 -m venv venv
$ source venv/bin/activate
$ touch pyproject.toml
$ echo 'print( )' > somefile
$ pip install black==23.7.0
...
$ black --check --include '^/somefile$' .
would reformat /home/sth/tst/somefile

Oh no! 💥 💔 💥
1 file would be reformatted.
$ pip install black==23.10.1
...
$ black --check --include '^/somefile$' .
No Python files are present to be formatted. Nothing to do 😴

Expected behavior

The file name matching for --include should work as it did previously, since the change was most likely unintentional and the matching of excludes still works the old way.

Environment

  • Black's version: 23.10.1
  • OS and Python version: Ubuntu 22.04, Python 3.10.12
@sth sth added the T: bug Something isn't working label Oct 24, 2023
@sth
Copy link
Contributor Author

sth commented Oct 27, 2023

Fixed in #3976

@sth sth closed this as completed Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant