我在我的 python 项目中使用预提交钩子已经有 5 年了。
我用诗歌来管理我所有的依赖,并且已经达到了一个相当稳定的状态。就像我说的,直到今天下午,我一直在使用它,问题绝对为零。
出于某种原因,一些挂钩无法运行,并显示“找不到命令”。特别是
flake8
和bandit
.
如果我手动运行
poetry run flake8
或 poetry run bandit
它们对我的任何回购文件都按预期工作。但是,当尝试提交时,我得到以下信息
我在这里错过了什么?为什么有些钩子运行没有问题,但是这两个钩子却失败了?我一辈子都弄不明白。
FTR 这是我的配置文件
---
repos:
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: python
types: [python]
args: [--skip-string-normalization]
exclude: (docs|tsa/alembic/)
- id: flake8
name: flake8
entry: poetry run flake8
language: python
types: [python]
args: [--max-line-length=88]
exclude: (docs|tsa/alembic/)
- id: pylint
name: pylint
entry: poetry run pylint
language: python
types: [python]
exclude: (docs|tsa/alembic/)
- id: isort
name: isort
entry: poetry run isort
language: python
types: [python]
- id: shellcheck
name: shellcheck
entry: poetry run shellcheck
language: system
types: [shell]
- id: mypy
name: mypy
entry: poetry run mypy
language: python
types: [python]
exclude: docs/*
- id: bandit
name: bandit
entry: poetry run bandit
language: python
types: [python]
exclude: tests/*
- id: sqlfluff
name: sqlfluff
entry: poetry run sqlfluff fix --force --dialect postgres
language: python
types: [sql]
我正在遵循我用于 30 多个 python 项目的相同工作流程:
使用我的所有依赖项(包括 black、flake8、mypy 等)创建 poetry virtualenv。
转到 repo 的根目录,运行
pre-commit-install
并开始提交代码。老实说不知道发生了什么。