带有 git 预提交钩子的 CalledProcessError

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

我在安装预提交挂钩时遇到了障碍。根据下面的错误,钩子安装在目录

C:\\Users\\dangler\\.cache\\pre-commit\\repoith5dg7x\\py_env-default\\Scripts\\python.EXE
中找不到python exe(该文件夹中不存在python.EXE......应该吗?)。在过去的几个小时里我一直在尝试解决这个问题,但没有成功。希望有一个解决方案,也许我已经搜索了错误的地方。

(fiddle-env) PS C:\Users\dangler\Documents\projects\fiddle> pre-commit clean
(fiddle-env) PS C:\Users\dangler\Documents\projects\fiddle> pre-commit install
(fiddle-env) PS C:\Users\dangler\Documents\projects\fiddle> git commit -am "README file with links"
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\dangler\\.cache\\pre-commit\\repookmqanwy\\py_env-default\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 3221225781
expected return code: 0
stdout: (none)
stderr: (none)
Check the log at C:\Users\dangler\.cache\pre-commit\pre-commit.log

.pre-commit-config.yml
文件是这样的:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.4.0
    hooks:
        -   id: double-quote-string-fixer
        -   id: check-added-large-files
        -   id: check-ast
        -   id: check-json
        -   id: check-yaml
        -   id: end-of-file-fixer
        -   id: no-commit-to-branch
        -   id: fix-encoding-pragma
        -   id: trailing-whitespace
-   repo: https://github.com/pre-commit/mirrors-autopep8
    rev: 'v1.4.4'  # Use the sha / tag you want to point at
    hooks:
        -   id: autopep8

git conda pre-commit-hook pre-commit pre-commit.com
3个回答
8
投票

我可以通过使用以下命令降级虚拟环境来解决此问题:

pip install virtualenv==20.0.33

然后安装预提交挂钩。更多信息:

https://github.com/ContinuumIO/anaconda-issues/issues/12094#issuecomment-708557750


0
投票

我通过将系统

virtualenv
升级到最新版本成功解决了这个相对无用的错误。发布,因为这必须比发布的强制降级解决方案更好:

python3 -m pip install --upgrade virtualenv

为了确保系统上没有留下旧的软件包,我还清除了我的缓存(我不知道这是否有必要):

rm -rf ~/.cache/pre-commit/

然后重新运行预提交,没有出现(意外的)错误:

git add .
git commit

0
投票

here所述,对于 isort,请尝试将 pre-commit-hooks 的版本更新为 v4.4.0,如下所示。

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0

可能还需要更新 autopep8 版本

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