python - 忽略黑色格式化程序的 pyproject.toml 文件中的 Django 迁移
问题描述
我刚刚为我的 Django 存储库设置了Black和Pre-Commit 。
我使用了我遵循的教程中的 Black 的默认配置,它运行良好,但我无法从中排除我的迁移文件。
这是我一直使用的默认配置:
pyproject.toml
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
我使用Regex101.com来确保^.*\b(migrations)\b.*$
匹配apps/examples/migrations/test.py
.
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| ^.*\b(migrations)\b.*$
)/
'''
当我将该正则表达式行添加到我的配置文件并运行pre-commit run --all-files
时,它会忽略该.git
文件夹,但仍会格式化迁移文件。
解决方案
将迁移排除添加到您的.pre-commit-config.yaml
文件中
- id: black
exclude: ^.*\b(migrations)\b.*$
推荐阅读
- flutter - 用 Future.delayed 重置动画是颤振的好习惯吗?
- reactjs - 在反应中将授权传递给cloudinary
- python - 如何在python中打开和读取子文件夹中的文件?
- angular - 没有收到从一个组件传递到另一个组件的角度路由器参数值?
- r - ggplot中的几个任意图例(直方图)
- python - 为什么我使用 Airflow 的 LocalExecutor 得到 ConnectionRefusedError?
- php - 如何在 ActiveCollab 中返回项目任务列表
- javascript - 递归迭代以验证模式
- c# - JObject.ToObject 与模型状态错误
- c++ - 如何将对象数据成员传递给 C++ 中的 lambda 函数?