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

pyenv - missing interpreters should be skipped #381

Closed
pszynk opened this issue Feb 8, 2021 · 1 comment
Closed

pyenv - missing interpreters should be skipped #381

pszynk opened this issue Feb 8, 2021 · 1 comment

Comments

@pszynk
Copy link

pszynk commented Feb 8, 2021

This is pretty much the same scenario as described in #252.
Problem shown by @florimondmanca is still present and the solution he presented isn't necessarily the desired outcome for every use-case.

Expected behavior

Only local python interpreter versions should be considered when using pyenv local.

Actual behavior

If we add python interpreter with pyenv global 3.6.12 (for example) the nox session is executed. Otherwise we got an error:

RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.6'

But what if we want nox to skip session for this python version?


Original issue bellow:

Describe the bug

The shims inserted by pyenv into the shell fool the py.path.local.sysfind() call made here, and results in Nox not correctly skipping missing interpreters.

How to reproduce

  • Have pyenv installed with at least 2 different Python minor versions.

    • Docker setup (installing may take a while):
$ docker pull themattrix/pyenv
$ docker run --rm -it themattrix/pyenv bash
# pyenv install 3.6.5
# pyenv install 3.7.0
# pyenv global 3.7.0
# pip install nox
  • Sample noxfile.py:
import nox


@nox.session(python=["3.6", "3.7"])
def test(session):
    pass
  • Copy-paste, then run $ pbpaste > noxfile.py on macOS, or in the Docker container:
# apt update
# apt install nano
# touch noxfile.py
# nano noxfile.py
... Paste contents within nano ...
  • Run $ nox.

Expected behavior

All sessions except the one using the Python version currently setup by pyenv (3.7 in my case) should be skipped, as explained in the docs

Actual behavior

Nox tries to run all versions, and fails. In my case, it fails on 3.6.

Full output:

$ nox
nox > Running session test-3.6
nox > Creating virtualenv using python3.6 in .nox/test-3-6
nox > Command /Users/florimond/.pyenv/versions/3.7.3/bin/python3.7 -m virtualenv /Users/florimond/Desktop/nox-pyenv/.nox/test-3-6 -p python3.6 failed with exit code 127:
pyenv: python3.6: command not found

The `python3.6' command exists in these Python versions:
  3.6.8

Running virtualenv with interpreter /Users/florimond/.pyenv/shims/python3.6
nox > Session test-3.6 failed.
nox > Running session test-3.7
nox > Creating virtualenv using python3.7 in .nox/test-3-7
nox > Session test-3.7 was successful.
nox > Ran multiple sessions:
nox > * test-3.6: failed
nox > * test-3.7: success

Extra debugging material

  • Output of $ pyenv versions on my machine:
  system
  2.7.15
  3.5.6
  3.6.8
* 3.7.3 (set by /Users/florimond/.pyenv/version)
  • Output of checking for Python versions on my machine:
$ which python3.6
/Users/florimond/.pyenv/shims/python3.6
$ which python3.7
/Users/florimond/.pyenv/shims/python3.7
$ python3.6 -V
pyenv: python3.6: command not found


The `python3.6' command exists in these Python versions:
  3.6.8

$ python3.7 -V
Python 3.7.3
  • Output of $ nox -l on my machine:
$ nox -l
Sessions defined in /Users/florimond/Desktop/nox-pyenv/noxfile.py:

* test-3.6
* test-3.7

sessions marked with * are selected, sessions marked with - are skipped.

Possible solutions

There's a difference in output when running sysfind() on a version that's available but not selected, and the version that's currently selected. Example in my case (running 3.7 with 3.6.8 available):

>>> import py
>>> py.path.local.sysfind("python3.6")
local('/Users/florimond/.pyenv/shims/python3.6')
>>> py.path.local.sysfind("python3.7")
local('/Users/florimond/.pyenv/versions/3.7.3/bin/python3.7')
>>> 

We could detect that we're running under pyenv, and if so only use the result from sysfind() if it doesn't contain shims in the path?

(We shouldn't rely on the output of sysfind to detect that we're using pyenv though, because the .pyenv shown there is the PYENV_ROOT, and that is configurable. I'd suggest to make a $ pyenv --version call instead.)

@theacodes
Copy link
Collaborator

Let's re-open the previous issue instead of opening new ones.

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

No branches or pull requests

2 participants