预提交挂钩:可执行<hook_name>未找到

问题描述 投票:0回答:1

我尝试在

pre-commit
上使用
VSCode

我使用

ruff
安装了
black
mypy
flake8
poetry

预提交-config.yaml

default_language_version:
    python: python3.10

repos:
  - repo: local

    hooks:

      - id: ruff
        name: ruff
        entry: ruff
        language: python
        types: [python]
        args: [
          --fix,
          --config=app/pyproject.toml
        ]

      - id: black
        name: black
        entry: black
        language: python
        types: [python]
        args: [
          --config=app/pyproject.toml
        ]

      - id: mypy
        name: mypy
        entry: mypy
        language: python
        types: [python]
        args: [
          --ignore-missing-imports,
          --check-untyped-defs,
          --no-implicit-optional,
          --config-file=app/pyproject.toml
        ]

      - id: flake8
        name: flake8
        entry: flake8
        language: python
        types: [ python ]
        args: [
          --config=./app/.flake8
        ]

我安装了

pre-commit
:

pre-commit install
> pre-commit installed at .git/hooks/pre-commit

.git/hooks/预提交

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/Users/serg/CODING/__samolet__/lk/.venv/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

之后我尝试提交我的代码并得到这样的错误:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
ruff.....................................................................Failed
- hook id: ruff
- exit code: 1

Executable `ruff` not found

black....................................................................Failed
- hook id: black
- exit code: 1

Executable `black` not found

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

Executable `mypy` not found

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

Executable `flake8` not found

我在 GitHub 上发现了类似的问题:未找到预提交挂钩可执行文件。但这对我没有帮助。

我尝试过:

  • pre-commit uninstall && pre-commit install
  • pre-commit clean && pre-commit install-hooks
    .

但是没有成功。

有什么想法可以解决这个问题吗?

git pre-commit-hook pre-commit pre-commit.com
1个回答
0
投票

您已经编写了自定义

repo: local
钩子(这是框架的逃生舱口),但没有正确配置它们

如果您使用受支持的存储库格式,这本来可以毫无问题地工作,但您已经绕过了框架,现在正在收获后果:)

即使修复安装(您需要添加

additional_dependencies: [...]
以确保安装完毕),您也有一个 fork 炸弹,因为您没有正确复制配置

tl;dr:使用上游存储库,而不是

repo: local
/
language: system
,除非你知道自己在做什么(即使这样,你也需要在框架外进行手动设置,从而对贡献者造成伤害)


免责声明:我写了预提交

© www.soinside.com 2019 - 2024. All rights reserved.