isidentical / teyit

Formatter for your Python unit tests
MIT License
104 stars 7 forks source link

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

Closed hugovk closed 2 years ago

hugovk commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 (https://github.com/psf/black/pull/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 commented 2 years ago

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

hugovk commented 2 years ago

Thanks!

rafrafek commented 2 years ago

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