Skip to content

Exclude property is not working in black #1584

Description

@kunal5

Describe the bug A clear and concise description of what the bug is.
Giving a file name to be excluded while running black via pre-commit is not excluding that file and formatting it.

To Reproduce Steps to reproduce the behavior:
.pre-commit-config.yml file

repos:
-   repo: https://github.com/ambv/black
    rev: stable # Replace by any tag/version: https://github.com/psf/black/tags
    hooks:
    -   id: black
        language_version: python3 # Should be a command that runs python3.6+
        args: ['--config=pyproject.toml', '-v']
-   repo: git@github.com:pre-commit/pre-commit-hooks
    rev: v2.0.0
    hooks:
    -   id: trailing-whitespace
    -   id: flake8
        args: ['--config=.flake8']
-   repo: git@github.com:pre-commit/mirrors-jshint
    rev: v2.12.0
    hooks:
    -   id: jshint
        language_version: 4.2.1
        entry: jshint squadrun/static/js/app/*
        args:
        - --exclude-path=squadrun/static/js/app/.jshintignore
        exclude: squadrun/static/js/libs/*
-   repo: git@github.com:SquadRun/mirrors-jscs
    sha: c7807cc8634375013f90942c5d927e3f7c55ab6b
    hooks:
    -   id: jscs
        language_version: 4.2.1
        entry: jscs squadrun/static/js/app/
        exclude: squadrun/static/js/libs/*
-   repo: local
    hooks:
    -   id: squadrun_linter
        entry: ./shell_scripts/squadrun_linter.sh
        name: squadrun_linter
        language: script
        files: ‘’

My pyproject.toml file

[tool.black]
target-version = ['py27']
line-length = 120
include = '\.pyi?$'
exclude = '''
(
  /(
      \.eggs         # exclude a few common directories in the
    | \.git          # root of the project
    | \.hg
    | \.mypy_cache
    | \.tox
    | \.venv
    | _build
    | buck-out
    | build
    | dist
    | migrations
  )/
  | foo.py           # also separately exclude a file named foo.py in
                     # the root of the project
  | apps/core/migrations/0002_auto_20200707_1828.py
)
'''

Here I have explicitly given the name of the file to be excluded i.e. apps/core/migrations/0002_auto_20200707_1828.py
3. See error
This file is not excluded. Here is the snapshot for running black command. apps/core/migrations/0002_auto_20200707_1828.py got successfully formatted.
Screenshot 2020-08-11 at 7 14 49 PM

How can I fix this?
Please help!
Thanks!

  • Version: stable version
  • OS and Python version: [e.g. MacOS/Python 2.7.]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: configurationCLI and configurationT: bugSomething isn't working

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions