I'm trying to use pre-commit
while working on a PR for pop-tools
. When trying to commit, I get the following error:
[WARNING] Unstaged files detected. [INFO] Stashing unstaged files to /glade/u/home/rbrady/.cache/pre-commit/patch1590692934. [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... [INFO] Restored changes from /glade/u/home/rbrady/.cache/pre-commit/patch1590692934. An unexpected error has occurred: CalledProcessError: command: ('/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/bin/python', '-mpip', 'install', '.') return code: 1 expected return code: 0 stdout: (none) stderr: Traceback (most recent call last): File "/glade/work/rbrady/miniconda3/envs/pop-tools-dev/lib/python3.8/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/glade/work/rbrady/miniconda3/envs/pop-tools-dev/lib/python3.8/runpy.py", line 86, in _run_code exec(code, run_globals) File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/__main__.py", line 23, in <module> from pip._internal.cli.main import main as _main # isort:skip # noqa File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 10, in <module> from pip._internal.cli.autocompletion import autocomplete File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module> from pip._internal.cli.main_parser import create_main_parser File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module> from pip._internal.cli import cmdoptions File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module> from pip._internal.cli.progress_bars import BAR_TYPES File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 12, in <module> from pip._internal.utils.logging import get_indentation File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/utils/logging.py", line 18, in <module> from pip._internal.utils.misc import ensure_dir File "/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 20, in <module> from pip._vendor import pkg_resources ImportError: cannot import name 'pkg_resources' from 'pip._vendor' (/glade/u/home/rbrady/.cache/pre-commit/repo4_mumozy/py_env-python3.8/lib/python3.8/site-packages/pip/_vendor/__init__.py)
A log is available here, but says basically the same thing: Check the log at /glade/u/home/rbrady/.cache/pre-commit/pre-commit.log
.
miniconda3
folder and reinstalling miniconda, since sometimes things get tripped up there. pre-commit
cache folder completely.pip
to a version earlier than 20.1.1
.pre-commit
to a version earlier than 2.4.0
Not sure what's going on here. Googling wasn't of much help. Couldn't find anyone referencing this error: ImportError: cannot import name 'pkg_resources' from 'pip._vendor'
.
Perhaps this has something to do with python 3.8?
this doesn't help figure out what is going wrong, but what if you stash the changes yourself?
$ git stash $ git commit $ git stash apply
@Riley Brady, try cleaning the cache with
pre-commit gc && pre-commit uninstall && pre-commit install
And run pre-commit run --all-files
to confirm that things are working again
Actually, use pre-commit run
as a check
@Anderson Banihirwe, no luck. Same error following those steps.
Okay
give me a second to look at the logs
@Michael Levy that doesn't help either, stashing before committing. It breaks on the git commit
step.
Can you post the content of your .pre-commit-hooks.yaml
file?
Looking back at your error message, I think I misread something... I thought the
[INFO] Restored changes from /glade/u/home/rbrady/.cache/pre-commit/patch1590692934
was indicating that the error happened when restoring changes, rather than that being the last good step... sorry about that
Can you post the content of your
.pre-commit-hooks.yaml
file?
Never mind.. I hadn't seen that this is pop-tools
:slight_smile:
I am not :100: convinced that the following is going to work, but it is worth trying.
How about updating the hooks:
repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.2.3 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-docstring-first - id: check-yaml - id: double-quote-string-fixer - repo: https://github.com/ambv/black rev: 19.3b0 hooks: - id: black args: ["--line-length", "100", "--skip-string-normalization"] - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.1 hooks: - id: flake8 - repo: https://github.com/asottile/seed-isort-config rev: v1.9.0 hooks: - id: seed-isort-config - repo: https://github.com/pre-commit/mirrors-isort rev: v4.3.20 hooks: - id: isort args: ["-w", "100"]
followed by
pre-commit autoupdate
git add . && pre-commit run
No, that didn't work unfortunately. I updated flake8
to 3.8.1 and ran those commands. I did this with and without blacken-docs as a hook. Are you reproducing this error when trying to run pre-commit on pop-tools?
Is pre-commit
installed in your base
environment?
No it's not
Just installed it in base and still had the issue.
I.e. install in base then activate pop-tools-dev
and trying running it.
Do you have setuptools
in your base
environment?
Yes
Are you reproducing this error when trying to run pre-commit on pop-tools?
Yes
abanihi at casper26 in ~/work/devel/ncar/pop-tools on update-pooch-downloader $ pre-commit run --verbose --all-files Trim Trailing Whitespace.................................................Failed - hook id: trailing-whitespace - duration: 0.14s - exit code: 1 - files were modified by this hook Fixing pop_tools/input_templates/tx1v1_vert_grid Fix End of Files.........................................................Failed - hook id: end-of-file-fixer - duration: 0.13s - exit code: 1 - files were modified by this hook Fixing docs/Makefile Fixing .coveragerc Check docstring is first.................................................Passed - hook id: check-docstring-first - duration: 0.09s Check Yaml...............................................................Passed - hook id: check-yaml - duration: 0.26s Fix double quoted strings................................................Passed - hook id: double-quote-string-fixer - duration: 0.08s black....................................................................Passed - hook id: black - duration: 0.68s All done! ✨ 🍰 ✨ 17 files left unchanged. Flake8...................................................................Passed - hook id: flake8 - duration: 0.86s seed isort known_third_party.............................................Passed - hook id: seed-isort-config - duration: 0.09s isort....................................................................Passed - hook id: isort - duration: 1.12s blacken-docs.............................................................Passed - hook id: blacken-docs - duration: 0.64s
I have to run some errands. When I'm back I'll see if I'm reproducing this locally (on my desktop) for pop-tools
and if it's something that's happening e.g. at climpred
as well..
Ran it locally on pop-tools
. First did pre-commit autoupdate
and then when I ran it, I was told that flake8
migrated to https://gitlab.com/pycqa/flake8
, so I switched that out for the repo on the config file and changed the rev to 3.8.2
and it worked. Let me see if that's the case on cheyenne.
Hm I changed out the repo for pre-commit on cheyenne and it didn't work. Switched to an interactive node on casper and it worked. Not really sure what's going on here.
Hm I changed out the repo for pre-commit on cheyenne and it didn't work. Switched to an interactive node on casper and it worked. Not really sure what's going on here.
It's weird that it works on Casper and not on Cheyenne...
Yeah they're both of course accessing the same miniconda folder and cache on glade. I'll go forward with this for now and will let you know if anything else comes up.
Last updated: May 16 2025 at 17:14 UTC