Skip to content

Black formatter not respecting pyproject.toml exclude #7047

Closed
@Angry-Potato

Description

@Angry-Potato

Environment data

  • VS Code version: 1.37.1
  • Extension version (available under the Extensions sidebar): 2019.8.30787
  • OS and version: macOS Mojave 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: black==19.3b0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Jedi

Expected behaviour

On save, Black will not format files that are excluded by pyproject.toml.

Actual behaviour

Black formats files regardless.

Steps to reproduce:

  1. Make a pyproject.toml file in your project, e.g.:
[tool.black]
exclude = '(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|.*\/models\.py.*|.*\/models\/.*)'
  1. Create a models.py file, with a formatting problem:
# note space before print
 print("This line will be printed.")

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> ~/anaconda2/envs/py_dev/bin/python -m black --config ~/work/example/pyproject.toml --diff --quiet ~/work/example/models.py.78c71eac353ea0a0b304502b320f3b03.py
cwd: ~/work/example
> ~/anaconda2/envs/py_dev/bin/python -m black --config ~/work/example/pyproject.toml --diff --quiet ~/work/example/models.py.78c71eac353ea0a0b304502b320f3b03.py
cwd: ~/work/example

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

> ~/anaconda2/envs/py_dev/bin/python -m black --config ~/work/example/pyproject.toml --diff --quiet ~/work/example/models.py.78c71eac353ea0a0b304502b320f3b03.py
cwd: ~/work/example
> ~/anaconda2/envs/py_dev/bin/python -m black --config ~/work/example/pyproject.toml --diff --quiet ~/work/example/models.py.78c71eac353ea0a0b304502b320f3b03.py
cwd: ~/work/example

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions