pre-commit-ci / issues

public issues for https://pre-commit.ci
16 stars 3 forks source link

Set Python version to 3.9 or 3.10? #117

Closed hugovk closed 2 years ago

hugovk commented 2 years ago

I'm trying to add the https://github.com/isidentical/teyit/blob/master/.pre-commit-hooks.yaml hook to a config file: https://github.com/jazzband/tablib/pull/520

Teyit requires Python 3.9+.

Originally the teyit hook specified language_version: python3.9:

But that failed when trying to run in GitHub Actions with 3.10:

[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)

So we changed the teyit hook from language_version: python3.9 to language_version: python3, because the docs say it is for when "you only want to run the hooks on a specific version", not set a minimum:

However, that now fails on pre-commit.ci:

        ERROR: Could not find a version that satisfies the requirement refactor==0.4.1 (from teyit) (from versions: none)
        ERROR: No matching distribution found for refactor==0.4.1

https://results.pre-commit.ci/run/github/1535009/1649052579.J6UPhLP3Qwqv8gKg0hRmlQ

I think that's because the refactor dependency requires Python 3.9+, and as far as I can tell pre-commit.ci is using 3.8 by default:

However, that says 3.9 and 3.10 are available.

Two questions:

  1. Hook config: can/should a hook define the minimum Python required?

  2. User config: How can we tell pre-commit.ci to use Python 3.9 or 3.10?

Thanks!

asottile commented 2 years ago

if you need a specific version of python, use language_version: python3.9

(there's nothing special about pre-commit.ci here -- this is the same as what you'd use for pre-commit in general)

hugovk commented 2 years ago

GitHub Actions pass, pre-commit.ci failure

Adding to .pre-commit-config.yaml (https://github.com/hugovk/tablib/pull/2/commits/c3a2912174ea633c0e52285f8684ce8026e88c3a):

  - repo: https://github.com/isidentical/teyit
    rev: 0.4.2
+   language_version: python3.9
    hooks:
      -   id: teyit

Passes on GitHub Actions with Python 3.10 but fails on pre-commit.ci with:

build attempt 1...
    => error
    [WARNING] Unexpected key(s) present on https://github.com/isidentical/teyit: language_version
    [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: ('/pc/clone/3VvRyaCJTkGU1G19fpOhzQ/py_env-python3/bin/python', '-mpip', 'install', '.')
    return code: 1
    expected return code: 0
    stdout:
        Processing /pc/clone/3VvRyaCJTkGU1G19fpOhzQ
          Installing build dependencies: started
          Installing build dependencies: finished with status 'done'
          Getting requirements to build wheel: started
          Getting requirements to build wheel: finished with status 'done'
          Preparing metadata (pyproject.toml): started
          Preparing metadata (pyproject.toml): finished with status 'done'

    stderr:
        ERROR: Could not find a version that satisfies the requirement refactor==0.4.1 (from teyit) (from versions: none)
        ERROR: No matching distribution found for refactor==0.4.1

    Check the log at /pc/pre-commit.log

https://results.pre-commit.ci/run/github/165720157/1649084553.rtorpksQTiud39G_P4gvtQ

https://github.com/hugovk/tablib/pull/2


GitHub Actions failure, pre-commit.ci pass

Switching back to teyit 0.4.1 that has language_version: python3.9 in .pre-commit-hooks.yaml and using .pre-commit-config.yaml:

   - repo: https://github.com/isidentical/teyit
-    rev: 0.4.2
-    language_version: python3.9
+    rev: 0.4.1
     hooks:
       -   id: teyit

Passes on pre-commit.ci but fails on GitHub Actions with Python 3.10:

An unexpected error has occurred: CalledProcessError: command: ('/home/runner/work/tablib/tablib/.tox/lint/bin/python', '-mvirtualenv', '/home/runner/.cache/pre-commit/reposwhrdk42/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)

Questions

Is the only option to have teyit specify 3.9 in its hook, and then make sure the GitHub Actions linter is also 3.9?

And do users also need to specifically have 3.9 locally to use git pre-commit, and not 3.10?

What would happen if another tool only supported 3.10+?

Thanks again!

asottile commented 2 years ago

your diff is invalid by the way:

    [WARNING] Unexpected key(s) present on https://github.com/isidentical/teyit: language_version

and again, there's nothing special about pre-commit.ci here -- that value is passed opaquely to virtualenv -- I believe your feature request is to have virtualenv support comparison operators ("pick me the newest that satisfies blah") or whatever