We are using pre-commit to format our Python code using black with the following configuration in .pre-commit-config.yaml
:
repos:
- repo: https://github.com/ambv/black
rev: 20.8b1
hooks:
- id: black
language_version: python3.7
As our packages are tested against and used in different Python versions (e.g. 3.7
, 3.8
, 3.9
) I want to be able to use the pre-commit Hook on different Python versions. But when committing Code e.g. on Python 3.8
, I get an error due to the language_version
in my configuration (see above):
C:\Users\FooBar\Documents\Programmierung\foo (dev -> origin)
λ git commit -m "Black file with correct black version"
[INFO] Initializing environment for https://github.com/ambv/black.
[INFO] Installing environment for https://github.com/ambv/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('c:\\users\\FooBar\\anaconda\\python.exe', '-mvirtualenv', 'C:\\Users\\FooBar\\.cache\\pre-commit\\repobmlg3b_m\\py_env-python3.7', '-p', 'python3.7')
return code: 1
expected return code: 0
stdout:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
stderr: (none)
Check the log at C:\Users\FooBar\.cache\pre-commit\pre-commit.log
How can I enable the pre-commit Hook on different Python-Versions e.g. only on Python 3?
Thanks in advance!
language_version: python3
! – Potable