Skip to content

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

@ichard26

Description

@ichard26

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)
)
)

Metadata

Metadata

Assignees

Labels

C: configurationCLI and configurationT: bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions