提问人:p1r4t3 提问时间:10/24/2023 最后编辑:p1r4t3 更新时间:10/24/2023 访问量:87
运行预提交,不包括多个钩子的目录
Running pre commits, excluding a directory for multiples hooks
问:
我正在尝试配置预提交以避免目录app/test/
我可以直接在钩子上排除它,例如avec mypy:
在cmd行中:mypy . --exclude ^app/test/$
在 pre-commit.yaml 文件中
- id: mypy
name: mypy
entry: .
args: ["--exclude", "^app/test/$"]
language: python
types: [python]
这工作得很好。
我想直接在提交前配置(https://pre-commit.com/#top_level-exclude)中排除它,因为我使用的是多个钩子
但我无法让它工作。到目前为止,我已经尝试在我的预提交文件中组合这样的东西:
exclude : ^app/test/$
repos :
[...]
你对我应该如何做到这一点有任何想法吗?
编辑 1
谢谢你的回答。我确实犯了一个错误,我的条目是.entry: mypy .
我也忘记了它在我的预提交文件中。我不太确定它在做什么,但如果没有它,排除,即使作为一个论点也不起作用。pass_filenames: false
所以我的预提交文件看起来像这样:
- id: mypy
name: mypy
entry: mypy .
args: ["--exclude", "^app/test/$", "--ignore-missing-imports"]
language: python
types: [python]
pass_filenames: false
因此,它可能会更改您排除的某些结果。
为了听从您的建议,我已将钩子更改为:(删除条目)
- id: mypy
name: mypy
args: ["--exclude", "^app/test/$", "--ignore-missing-imports"]
language: python
types: [python]
它不起作用,错误是:。Missing required key : entry
对于此配置:
- id: mypy
name: mypy
args: ["--exclude", "^app/test/$", "--ignore-missing-imports"]
language: python
types: [python]
pass_filenames: false
它也不起作用,错误是一样的:。Missing required key : entry
因此,我添加了没有的条目键:.
- id: mypy
name: mypy
entry: mypy
args: ["--exclude", "^app/test/$", "--ignore-missing-imports"]
language: python
types: [python]
它不起作用,但不排除目录
对于最后的配置:
- id: mypy
name: mypy
entry: mypy
args: ["--exclude", "^app/test/$", "--ignore-missing-imports"]
language: python
types: [python]
pass_filenames: false
它不起作用,我有以下错误:Missing target module
注意:我还没有使用它,但我也想使用 mypy 的标志。strict
我没有使用文件 mypy 的配置,我不想使用一个。
我可以尝试什么来避免覆盖mypy的条目或参数,但仍然排除目录,即作为全局参数?
谢谢
编辑 2
阅读评论,我忘记了一部分;我想在 CI 中运行我的预提交以避免著名的--no-verify
答:
您通过设置破坏了 <=> 集成(这甚至不起作用?我怀疑这不是您的实际代码,而是您编写了这也破坏了集成,但以一种双重方式破坏了您的所有代码)pre-commit
mypy
entry: .
args: [.]
mypy也是一个棘手的问题,因为它默认会跟随你的导入 - 所以你需要从传递的文件和mypy配置中排除它
我的建议:
- 不要覆盖 或 Mypy - 如果你这样做,不要添加它,因为它会双重 lint 所有内容并破坏文件过滤
entry
args
.
- 将特定模块添加到mypy的配置文件中以忽略它
免责声明:我写了预提交
评论
mypy
pass_filenames: false
args
ignore_errors = true
tool.mypy.overrides
评论