[Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter

18👍

Add the migration exclusion to your .pre-commit-config.yaml file

- id: black
  exclude: ^.*\b(migrations)\b.*$

9👍

That’s the solution to the problem: pyproject.toml

[tool.black]
exclude = '''
/(
  | migrations
)/

'''

2👍

Try this (note last line):

[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
    \.git
  | \.hg
  | \.mypy_cache
  | \.tox
  | \.venv
  | _build
  | buck-out
  | build
  | dist
  | migrations
)/
'''
👤tee

2👍

Maintaining two different places for exclude config doesn’t look good if avoidable and will not work well for the CI either (should you want to dry run black in the PR checks).
Adding the following works for the pyproject.toml and then you can run the same in the pre-commit hook and CI:

[tool.black]
...
exclude = '''

(
  /(
    ...
    | .+/migrations
  )/
)
'''
👤maylon

1👍

to just extend the default exlusions (without adding the whole list), you can just do:

[tool.black]
extend-exclude = '''
/(
  | migrations
)/
'''
👤fvmac

Leave a comment