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

could not find interpreter after discovering, proposing, and accepting #3174

Open
thomasgilgenast opened this issue Dec 15, 2023 · 0 comments
Labels
help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.

Comments

@thomasgilgenast
Copy link

Hello! I am a huge fan of tox and greatly appreciative of the work it takes to develop and maintain it - thank you!

Issue

Recently I have been encountering skipped because could not find python interpreter with spec issues while trying to run tox in github actions.

  • I don't need to test multiple Python versions in CI, so I would prefer to avoid tox-gh if possible.
  • I have a non-trivial tox-requires, so my tox run is running in an auto-provisioned .tox/.tox env.
  • I do not mention skip_missing_interpreters in my tox.ini.

In all cases, I set up python3.10 in my GHA YAML:

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

and this step succeeds with output

Run actions/setup-python@v4
  with:
    python-version: [3](https://github.com/.../.../actions/runs/.../job/...#step:3:3).10
    check-latest: false
    token: ***
    update-environment: true
    allow-prereleases: false
Installed versions
  Successfully set up CPython (3.10.13)

When I set

[testenv]
basepython = python3

in tox.ini, I get the following relevant tox -vvv output for any testenv I run (e.g. lint)

lint: 365 I find interpreter for spec PythonSpec(major=3) [virtualenv/discovery/builtin.py:58]
lint: 365 D discover exe for PythonInfo(spec=CPython3.10.13.final.0-64, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) in /opt/hostedtoolcache/Python/3.10.13/x64 [virtualenv/discovery/py_info.py:441]
lint: 366 D filesystem is case-sensitive [virtualenv/info.py:26]
lint: 367 D get interpreter info via cmd: /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10 /home/runner/work/.../.../.tox/.tox/lib/python3.10/site-packages/virtualenv/discovery/py_info.py fbWnRIbnNk0Gs39468WVb6cbKruZkksw gwnyWfGaj815vR6d55dkIPVTk9KVYv7q [virtualenv/discovery/cached_py_info.py:111]
lint: 637 D wrote python info of %s at (PosixPath('/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10'), PosixPath('/home/runner/.local/share/virtualenv/py_info/1/16ffcc7b051f840cfc860cf6e097c62dbc886225f5bf7c8ffd6a0f9b5902fc5b.json')) [virtualenv/app_data/via_disk_folder.py:151]
lint: 637 I proposed PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
lint: 638 D accepted PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:67]
lint: 664 W skipped because could not find python interpreter with spec(s): python3 [tox/session/cmd/run/single.py:49]

If I specify

[testenv]
basepython = python3.10

I get

lint: 426 I find interpreter for spec PythonSpec(major=3, minor=10) [virtualenv/discovery/builtin.py:58]
lint: 426 D discover exe for PythonInfo(spec=CPython3.10.13.final.0-64, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) in /opt/hostedtoolcache/Python/3.10.13/x64 [virtualenv/discovery/py_info.py:441]
lint: 427 D filesystem is case-sensitive [virtualenv/info.py:26]
lint: 429 D get interpreter info via cmd: /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10 /home/runner/work/.../.../.tox/.tox/lib/python3.10/site-packages/virtualenv/discovery/py_info.py nuSeDG9qS4srlMf6tK1DwPN85accotJq TxWUz0DsXkVu13R6WQrhh3jY5aSBkkat [virtualenv/discovery/cached_py_info.py:111]
lint: 758 D wrote python info of %s at (PosixPath('/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10'), PosixPath('/home/runner/.local/share/virtualenv/py_info/1/16ffcc7b051f840cfc860cf6e097c62dbc886225f5bf7c8ffd6a0f9b5902fc5b.json')) [virtualenv/app_data/via_disk_folder.py:151]
lint: 759 I proposed PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
lint: 759 D accepted PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:67]
lint: 790 W skipped because could not find python interpreter with spec(s): python3.10 [tox/session/cmd/run/single.py:49]

Finally, if I don't set basepython at all, I expect that tox will search for and find the interpreter tox is running within (in this case, an auto-provisioned interpreter in .tox/.tox), but I get:

lint: 352 I find interpreter for spec PythonSpec(path=/home/runner/work/.../.../.tox/.tox/bin/python) [virtualenv/discovery/builtin.py:58]
lint: 353 D discover exe for PythonInfo(spec=CPython3.10.13.final.0-64, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) in /opt/hostedtoolcache/Python/3.10.13/x64 [virtualenv/discovery/py_info.py:441]
lint: 353 D filesystem is case-sensitive [virtualenv/info.py:26]
lint: 354 D get interpreter info via cmd: /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10 /home/runner/work/.../.../.tox/.tox/lib/python3.10/site-packages/virtualenv/discovery/py_info.py YMBB32pzIvG9KY2lZhCaFs7ilTz0aEr4 ptThd4tnbH1aQJUvjpZZebtzIpmkVjne [virtualenv/discovery/cached_py_info.py:111]
lint: 621 D wrote python info of %s at (PosixPath('/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10'), PosixPath('/home/runner/.local/share/virtualenv/py_info/1/16ffcc7b051f840cfc860cf6e097c62dbc886225f5bf7c8ffd6a0f9b5902fc5b.json')) [virtualenv/app_data/via_disk_folder.py:151]
lint: 622 I proposed PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
lint: 622 D accepted PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10, exe=/home/runner/work/.../.../.tox/.tox/bin/python, platform=linux, version='3.10.13 (main, Aug 28 2023, 08:28:42) [GCC 11.4.0]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:67]
lint: 649 W skipped because could not find python interpreter with spec(s): /home/runner/work/.../.../.tox/.tox/bin/python [tox/session/cmd/run/single.py:49]

In all of these scenarios, it appears that tox

  • discovers the CPython3.10.13.final.0-64 interpreter I set up with actions/setup-python
  • proposes that interpreter
  • accepts that interpreter
  • skips the testenv because it can't find an interpreter that matches the spec

Naively, to me this seems like a bug: if the interpreter is discovered, proposed, and accepted (and no step in this process appears to have failed), then it feels like it should count as "found". It is also surprising to me that tox would not find the interpreter that tox itself is running from when basepython is not set. But I am sure I am just misunderstanding some detail about the process by which tox finds the interpreter.

I am happy to dive deeper into the debugging myself, but I wanted to ask for any rough guidance about how this process is supposed to work (for example, what step comes after "accepted" and is presumably failing? or what aspects are taken into account when trying to "match" a spec from basepython that might cause this interpreter to not be found?).

I am guessing that the interpreter is being "accepted" by virtualenv here

https://github.com/pypa/virtualenv/blob/5ad4de304a8e0344d0c3084c31f129119e50a377/src/virtualenv/discovery/builtin.py#L67

But it is not being found because this returns None:

self._base_python = self._get_python(base_pythons)

And this is maybe happening because of a FileNotFoundError or RuntimeError here:

try:
interpreter = self.creator.interpreter
except (FileNotFoundError, RuntimeError): # Unable to find the interpreter
return None

And beyond that it gets a bit tricky for me to sort through at first glance once it runs into the session.

I can reproduce this locally on MacOS, where if I set basepython = python3.10 and run tox from a Homebrew Python 3.10.13 virtualenv with tox installed, I get

ROOT: 92 I find interpreter for spec PythonSpec(path=/Users/.../git/.../venv/bin/python) [virtualenv/discovery/builtin.py:58]
ROOT: 92 D discover exe for PythonInfo(spec=CPython3.10.13.final.0-64, exe=/Users/.../git/.../venv/bin/python, platform=darwin, version='3.10.13 (main, Aug 24 2023, 22:36:46) [Clang 14.0.3 (clang-1403.0.22.14.1)]', encoding_fs_io=utf-8-utf-8) in /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10 [virtualenv/discovery/py_info.py:441]
ROOT: 93 D filesystem is not case-sensitive [virtualenv/info.py:26]
ROOT: 94 D got python info of %s from (PosixPath('/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/bin/python3.10'), PosixPath('/Users/.../Library/Application Support/virtualenv/py_info/1/2d6cbd8ca062199a98662f3310ba6286764b31353ea4bf55baab4dae9f4129d0.json')) [virtualenv/app_data/via_disk_folder.py:131]
ROOT: 94 D got python info of %s from (PosixPath('/opt/homebrew/opt/python@3.10/bin/python3.10'), PosixPath('/Users/.../Library/Application Support/virtualenv/py_info/1/eda7e54fe21129b67f77862937907ee926f057597a3e2fa1e18ac955e40912b3.json')) [virtualenv/app_data/via_disk_folder.py:131]
ROOT: 94 I proposed PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/homebrew/opt/python@3.10/bin/python3.10, exe=/Users/.../git/.../venv/bin/python, platform=darwin, version='3.10.13 (main, Aug 24 2023, 22:36:46) [Clang 14.0.3 (clang-1403.0.22.14.1)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:65]
ROOT: 94 D accepted PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/homebrew/opt/python@3.10/bin/python3.10, exe=/Users/.../git/.../venv/bin/python, platform=darwin, version='3.10.13 (main, Aug 24 2023, 22:36:46) [Clang 14.0.3 (clang-1403.0.22.14.1)]', encoding_fs_io=utf-8-utf-8) [virtualenv/discovery/builtin.py:67]
Traceback (most recent call last):
  File "/Users/.../git/.../venv/bin/tox", line 8, in <module>
    sys.exit(run())
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/run.py", line 41, in main
    result = provision(state)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/provision.py", line 122, in provision
    return run_provision(provision_tox_env, state)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/provision.py", line 141, in run_provision
    env_python = tox_env.env_python()
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/tox_env/python/virtual_env/api.py", line 155, in env_python
    return cast(Path, self.creator.exe)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/tox_env/python/virtual_env/api.py", line 126, in creator
    return self.session.creator
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/tox/tox_env/python/virtual_env/api.py", line 107, in session
    self._virtualenv_session = session_via_cli(env_dir, options=None, setup_logging=False, env=env)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/virtualenv/run/__init__.py", line 49, in session_via_cli
    parser, elements = build_parser(args, options, setup_logging, env)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/virtualenv/run/__init__.py", line 88, in build_parser
    element.handle_selected_arg_parse(options)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/virtualenv/run/plugin/seeders.py", line 32, in handle_selected_arg_parse
    return super().handle_selected_arg_parse(options)
  File "/Users/.../git/.../venv/lib/python3.10/site-packages/virtualenv/run/plugin/base.py", line 55, in handle_selected_arg_parse
    raise RuntimeError(msg)
RuntimeError: No implementation for PythonInfo(spec=CPython3.10.13.final.0-64, system=/opt/homebrew/opt/python@3.10/bin/python3.10, exe=/Users/.../git/.../venv/bin/python, platform=darwin, version='3.10.13 (main, Aug 24 2023, 22:36:46) [Clang 14.0.3 (clang-1403.0.22.14.1)]', encoding_fs_io=utf-8-utf-8)

Environment

In short, I am using tox==4.11.4 and virtualenv==20.25.0 which are both latest at the time of writing.

In GHA, I am using Python 3.10.13 provisioned via actions/setup-python@v4.

On local machine (MacOS), I am using Homebrew Python 3.10.13.

  • OS: Ubuntu 22.04.3 LTS (GHA runner v2.311.0, ubuntu-22.04 image)
Output of pip list of the host Python, where tox is installed
Package                               Version
------------------------------------- ----------
cachetools                            5.3.2
certifi                               2023.11.17
cffi                                  1.16.0
chardet                               5.2.0
charset-normalizer                    3.3.2
colorama                              0.4.6
cryptography                          41.0.7
distlib                               0.3.8
filelock                              3.13.1
fire                                  0.5.0
google-auth                           2.25.2
idna                                  3.6
importlib-metadata                    7.0.0
jaraco.classes                        3.3.0
jeepney                               0.8.0
keyring                               24.3.0
keyrings.google-artifactregistry-auth 1.1.2
more-itertools                        10.1.0
packaging                             23.2
pip                                   23.0.1
platformdirs                          4.1.0
pluggy                                1.3.0
pyasn1                                0.5.1
pyasn1-modules                        0.3.0
pycparser                             2.21
pyproject-api                         1.6.1
requests                              2.31.0
rsa                                   4.9
SecretStorage                         3.3.3
setuptools                            [65](https://github.com/.../.../actions/runs/.../job/...#step:8:66).5.0
six                                   1.16.0
termcolor                             2.4.0
tomli                                 2.0.1
tox                                   4.11.4
urllib3                               2.1.0
virtualenv                            20.25.0
virtualenv-seedhelper                 0.0.1
zipp                                  3.17.0

Minimal example

Unfortunately, I have not been able to identify a minimal example.

@gaborbernat gaborbernat added the help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.
Projects
None yet
Development

No branches or pull requests

2 participants