CalledProcessError with git pre-commit hook
Asked Answered
L

3

6

I'm hitting a snag installing pre-commit hooks. Based on the error below, the hook installation cannot find a python exe in the directory C:\\Users\\dangler\\.cache\\pre-commit\\repoith5dg7x\\py_env-default\\Scripts\\python.EXE (python.EXE doesn't exist in that folder... should it?). I’ve been trying to trouble shoot it for the past few hours, to no avail. Hoping a solution exists for this, and perhaps I've searched incorrect places for it.

(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

The .pre-commit-config.yml file is this:

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

Lachrymose answered 8/12, 2020 at 2:40 Comment(0)
L
8

I was able to resolve this by downgrading the virtual environment with this command:

pip install virtualenv==20.0.33

then installing the pre-commit hooks. More info:

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

Lachrymose answered 8/12, 2020 at 5:50 Comment(1)
Any thoughts on a solution when using Anaconda instead?Asis
N
2

I managed to resolve this relatively unhelpful error by upgrading my system virtualenv to the latest version. Posting as this has to be better than the posted solution of a forced downgrade:

python3 -m pip install --upgrade virtualenv

To ensure no old packages were left on the system, I also cleared my cache (I don't know if this is necessary or not):

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

Then re-running pre-commit ran without (unintended) errors:

git add .
git commit
Nealah answered 8/11, 2023 at 16:23 Comment(0)
C
0

As mentioned here for isort, try updating the version of pre-commit-hooks to v4.4.0 like so.

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

Updating the autopep8 version might also be required

Cuman answered 20/11, 2023 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.