Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-commit hook: python3 instead of python3.9 #14

Merged
merged 1 commit into from Apr 3, 2022

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Apr 2, 2022

I'm mostly using Python 3.10 locally and for CI linting, and currently it fails like this:

[INFO] Initializing environment for https://github.com/asottile/pyupgrade.
[INFO] Initializing environment for https://github.com/PyCQA/isort.
[INFO] Initializing environment for https://github.com/isidentical/teyit.
[INFO] Initializing environment for https://github.com/pre-commit/pygrep-hooks.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/asottile/pyupgrade.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/isidentical/teyit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/runner/work/tablib/tablib/.tox/lint/bin/python', '-mvirtualenv', '/home/runner/.cache/pre-commit/repostlq81p2/py_env-python3.9', '-p', 'python3.9')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.9'
    
stderr: (none)
Check the log at /home/runner/.cache/pre-commit/pre-commit.log
ERROR: InvocationError for command /home/runner/work/tablib/tablib/.tox/lint/bin/pre-commit run --all-files (exited with code 3)

Setting just python3 should be enough. For example, compare https://github.com/PyCQA/isort/blob/c6a41965247a858a0afd848fbebfca18b8983917/.pre-commit-hooks.yaml.

@isidentical
Copy link
Owner

One thing to note is that, teyit requires 3.9+ to work. From what I can assume python3 would mean any supported Python version, no?

@hugovk
Copy link
Contributor Author

hugovk commented Apr 3, 2022

The pre-commit docs say language_version is for when "you only want to run the hooks on a specific version", not for setting a minimum version:

Let's look at isort again. It supports Python 3.6+ but sets language_version: python3.

And Black also supports Python 3.6, but they removed language_version: python3 (psf/black#2430).

Similarly, https://github.com/pre-commit/pre-commit-hooks/blob/main/.pre-commit-hooks.yaml doesn't specify language_version.


Because language_version is to define a specific version, if we had teyit specifying 3.9, isort specifying 3.6, and let's imagine another specifying 3.7.

See the error in the first message.

To fix it, I'd need to split the CI into three different linting runs on the CI, each only running for a specific Python version.

And to commit locally, I'd potentially need three versions of Python installed when 3.10 should be enough.

@isidentical
Copy link
Owner

I see. Let's merge it as is then, thanks for the explanation @hugovk!

@isidentical isidentical merged commit 36eb546 into isidentical:master Apr 3, 2022
@hugovk hugovk deleted the patch-1 branch April 3, 2022 19:02
@hugovk
Copy link
Contributor Author

hugovk commented Apr 3, 2022

Thanks!

@rafrafek
Copy link

rafrafek commented Nov 7, 2022

language_version has to be completely removed from hook definition in order to use default_language_version in .pre-commit-config.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants