question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black fails to find python files

See original GitHub issue

Describe the bug Black, when run on a directory, fails to find python files contained in it.

To Reproduce Steps to reproduce the behavior: Directory structure:

tree src/cloudbuild 

src/cloudbuild
β”œβ”€β”€ build
β”‚Β Β  β”œβ”€β”€ build_args.py
β”‚Β Β  β”œβ”€β”€ build_result.py
β”‚Β Β  β”œβ”€β”€ build_tool.py
β”‚Β Β  β”œβ”€β”€ config
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ mypy_tool.ini
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pycodestyle_tool.ini
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pylint_tool.rc
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ python_toolchain.yaml
β”‚Β Β  β”‚Β Β  └── test_coverage_tool.rc
β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  └── tool
β”‚Β Β      β”œβ”€β”€ compile_tool.py
β”‚Β Β      β”œβ”€β”€ docstr_coverage_tool.py
β”‚Β Β      β”œβ”€β”€ __init__.py
β”‚Β Β      β”œβ”€β”€ mypy_tool.py
β”‚Β Β      β”œβ”€β”€ pycodestyle_tool.py
β”‚Β Β      β”œβ”€β”€ pylint_tool.py
β”‚Β Β      β”œβ”€β”€ python.py
β”‚Β Β      β”œβ”€β”€ python_report_tool.py
β”‚Β Β      └── unittest_tool.py
└── __init__.py
black src/cloudbuild/

All done! ✨ 🍰 ✨
1 file left unchanged.
black src/cloudbuild/build/tool/ 

No Python files are present to be formatted. Nothing to do 😴
black src/cloudbuild/build/tool/*

reformatted src/cloudbuild/build/tool/python.py
reformatted src/cloudbuild/build/tool/pycodestyle_tool.py
reformatted src/cloudbuild/build/tool/unittest_tool.py
reformatted src/cloudbuild/build/tool/mypy_tool.py
reformatted src/cloudbuild/build/tool/python_report_tool.py
reformatted src/cloudbuild/build/tool/pylint_tool.py
All done! ✨ 🍰 ✨

Expected behavior Running Black on a directory runs it on all python files within that directory and subdirectories.

Environment (please complete the following information):

  • Version: both black-19.10b0 and master
  • OS and Python version: Arch Linux, Python 3.7.2

Does this bug also happen on master? To answer this, you have two options: Yes

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
lordmauvecommented, Feb 3, 2020

I think this is still a bug: the exclude pattern should not match path components that were given on the command line.

The example given above was

black src/cloudbuild/build/tool/ 

No Python files are present to be formatted. Nothing to do 😴

So the user has told it to act on a specifically specified directory. It has then evaluated that directory against the default --exclude patterns and concluded it has nothing to do.

IMHO when given a directory as a CLI argument, black should consider the paths of items in the directory relative to the directory given when applying the --exclude pattern.

2reactions
knattencommented, Jan 30, 2020

Would you be willing to re-consider your default exclude patterns? We have several subfolders called build in our source code, and it caught me by surprise that these were excluded when I tried to format my source tree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The basics - Black 22.12.0 documentation
Black will only ever use one pyproject.toml file during an entire run. It doesn't look for multiple files, and doesn't compose configuration from...
Read more >
black's --include option not working in pre-commit to add ...
My assumption had been that pre-commit was supplying a list of files to black but, as a list of files appears to override...
Read more >
Setting up python Black on Visual Studio Code | by Marco Belo
Search for β€œpython formatting provider” and select β€œblack”. Now open/create a python file, write some code and save(Ctrl+s) it to see the magic...
Read more >
python-black - Package Control
There is no need to install black , but if you install it, it will not affect this package. ... Find this project...
Read more >
When trying to open a Python file, why does a black screen ...
It can also mean your Python's Interpreter Path Variable is not set in your advanced settings. So it attempts to read your .py...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found