I'm trying to set up pre-commit for my Repo. However there's something odd happening when trying to import the current pre-commit version.
I am installing pre-commit through conda using
$ conda install -c conda-forge pre_commit
I then enter into a Git controlled directory and run pre-commit and receive the following error...
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/jseiler/.cache/pre-commit/patch1562126919.
[INFO] Restored changes from /home/jseiler/.cache/pre-commit/patch1562126919.
An unexpected error has occurred: ValueError: invalid literal for int() with base 10: 'dev2'
Check the log at /home/jseiler/.cache/pre-commit/pre-commit.log
/home/jseiler/.cache/pre-commit/pre-commit.log has the following contents...
An unexpected error has occurred: ValueError: invalid literal for int() with base 10: 'dev2'
Traceback (most recent call last):
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/error_handler.py", line 46, in error_handler
yield
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/main.py", line 294, in main
return run(args.config, store, args)
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/commands/run.py", line 282, in run
for hook in all_hooks(config, store)
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 221, in all_hooks
for repo in root_config['repos']
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 222, in <genexpr>
for hook in _repository_hooks(repo, store, root_config)
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 197, in _repository_hooks
return _cloned_repository_hooks(repo_config, store, root_config)
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 181, in _cloned_repository_hooks
for hook in repo_config['hooks']
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 181, in <listcomp>
for hook in repo_config['hooks']
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/repository.py", line 122, in _hook
if parse_version(version) > parse_version(C.VERSION):
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/util.py", line 177, in parse_version
return tuple(int(p) for p in s.split('.'))
File "/fred/oz004/jseiler/miniconda3/envs/py3.7/lib/python3.7/site-packages/pre_commit/util.py", line 177, in <genexpr>
return tuple(int(p) for p in s.split('.'))
ValueError: invalid literal for int() with base 10: 'dev2'
Through some sleuthing, I have deduced that this error is related to the value of C.VERSION in pre_commit/constants.py. Instead of returning the current version as a string (should be "1.17.0"), it is returning 0.0.0dev2 causing the error to be thrown when we try to parse the version.
Any help or insight into this would be appreciated.
this is a dupe of #1059 -- but a different failure mode
somewhere you've got a .egg on your sys.path that's version "something.dev2" -- the upstream bug will eventually fix this: https://gitlab.com/python-devs/importlib_metadata/merge_requests/78
Hey @asottile , I checked that upstream PR and saw that it was merged.
I have updated pre_commit (even fully uninstalling and reinstalling) but am still getting this identical error. Is there something I missed here?
If you prefer, I can open an issue with importlib_metadata directly as the issue seems to be there.
Have you upgraded importlib-metadata -- you'll need at least version 0.19
I thought I had but I apparently hadn't, cheers!