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

File excluded even if explicitly passed via the command line when specified via --exclude #1572

Closed
ichard26 opened this issue Aug 7, 2020 · 0 comments · Fixed by #1591
Closed
Assignees
Labels
C: configuration CLI and configuration T: bug Something isn't working

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Aug 7, 2020

Describe the bug

--exclude is supposed to only apply to the recursive discovery of files. Not files explicitly passed to Black through the command line. This is a regression since #1032 was merged.

To Reproduce

  1. Create a directory for testing
  2. Create and activate a virtual enviroment
  3. Install Black on master using pip install git+git://github.com/psf/black
  4. Create two empty files:
    4.1. pyproject.toml so Black doesn't find a different configuration file up your directory structure
    4.2. test.py - this will be our test file
  5. Run black -v --exclude=test.py test.py
  6. Install Black 19.10b0 using pip install black==19.10b0
  7. Run black -v --exclude=test.py test.py
  8. Observe that on master the file was excluded and on stable the file was formatted.

Expected behavior

Black formats test.py since it was explicitly passed through the command line and --exclude should not touch such files like it.

Environment

  • Version: master (b59a524) and stable (19.10b0)
  • OS and Python version: Ubuntu 18.04.04 LTS and Python 3.8.1

Does this bug also happen on master?

Yes and also N/A - This is a regression

Additional context

I haven't looked into this bug that much, but the problem seems to be related to how even files passed via the command line are given to the recursive gen_python_files function as single Path object lists in get_sources.

black/src/black/__init__.py

Lines 605 to 610 in b59a524

elif p.is_file():
sources.update(
gen_python_files(
[p], root, None, exclude_regexes, report, get_gitignore(root)
)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: configuration CLI and configuration T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant