-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Missing interpreters aren't skipped under pyenv #252
Comments
Found the solution — I simply needed to activate all relevant Python versions in $ pyenv global 3.7.3 3.6.8 Then I don't think there's actually a bug in Nox at this point — if trying to use a Python version that's not installed by So I'm going to close this. 😄 Hopefully this helps anyone stumbling upon this issue? |
@pszynk brought up that Nox's behavior with pyenv may not be correct:
@pszynk to make sure I understand your issue correctly, you want Nox to not use any of the global pyenv interpreters if local pyenv interpreters are configured? |
@theacodes first of all thanks for your contribution, this is a great project. Sorry I didn't make myself clear and for the delayed response. I needed some time to investigate my issue. My conclusions: 1. Why did I get a
|
I'm not sure I really understand how this is an issue? Nox looks at the
path to discover pythons on unixes, and if it's on the path it's fair game.
I don't see how that's inconsistent with virtualenv's behavior? Can you
show me a case where Nox files pyenv's interpreter but virtualenv doesn't?
…On Wed, Feb 10, 2021 at 2:24 PM pszynk ***@***.***> wrote:
@theacodes <https://github.com/theacodes> first of all thanks for your
contribution, this is a great project.
Sorry I didn't make myself clear and for the delayed response. I needed
some time to investigate my issue.
My conclusions:
1. Why did I get a RuntimeError when running nox:
$ nox -s test -p 3.8
nox > Running session test-3.8
nox > Creating virtual environment (virtualenv) using python3.8 in .nox/test-3-8
nox > Command /home/user/.pyenv/versions/3.9.1/envs/nox/bin/python3.9 -m virtualenv /home/user/tmp/test-nox/.nox/test-3-8 -p python3.8 failed with exit code 1:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.8'
nox > Session test-3.8 failed.
This is due to my misuse of pyenv + pyenv-virtualenv (or a bug perhaps).
One of pyenv managed virtualenvs had a symbolic link: python3.8 -> python
but the python binary was in fact an interpreter version 3.9.1. How did
it happen, I've no idea, and I cannot reproduce this. Still I don't think
it really matters.
The point is that nox discovered an interpreter matching 3.8, while
virtualenv did not, and this can be an issue.
2. Python interpreter discovery is inconsistent between nox and virtualenv
:
Looking at both nox and virtualenv code I can see that an interpreter
discovery can be tricky. Question is, if this logic has to be implemented
by both packages? In case of the virtualenv this functionality is under
development. They offer a plugin-based approach python-discovery
<https://virtualenv.pypa.io/en/20.4.2/extend.html#python-discovery>,
which could be an answer when you want to consider only local
interpreters when using pyenv.
If nox should do interpreter discovery, could it possibly check if
virtualenv found the proper interpreter. Unfortunately virtualenv throws
only a generic RuntimeError on failure.
3. Solution with pyenv global <intepreter_1> <interpreter_2> ... is
inaccurate
In fact, there is no need to 'activate' pyenv environments, that is make
them local or global. nox will discover all interpreters installed by
pyenv regardless. aforementioned line:
https://github.com/theacodes/nox/blob/d6a0ba5f8a8d34198ecd381faf9093ab77c3cb5e/nox/virtualenv.py#L354
should discover all shims in pyenv directory: ~/.pyenv/shims/ and shims
for executables appear after command pyenv rehash
4. Should nox discover all pyenv installed interpreters?
The whole point of using pyenv locally is to create a specific
environment for your project. So if I'm executing nox in my workspace
directory, I'd expect it to stick to the environment I've prepared.
So yes, in my case the best solution would be to ignore all non-local
pyenv interpreters, but...
If sb is using pyenv to install multiple interpreter versions in a docker
container for testing purposes...
then I guess current solution is ok.
And If you want to execute only with a subset of interpreters with nox
there is always an --pythons option
4. Summary
Is it possible to make nox and virtualenv interpreter discovery
consistent?
The visibility of pyenv interpreters could be solved by virutalenv
discovery plugins.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#252 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5I45XYX7FTDKUO3Z7ZHTS6LMQHANCNFSM4I3N7ZFA>
.
|
The example would be the original issue. When you install new
I was mistaken about what really happens behind the scenes and I've fixed this in my previous comment. But the point is that For now, |
I reproduced the described behavior, but I'm still a little unsure on a few points.
Does it, though? Nox invokes $ virtualenv -p python3.7 env
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7' $ nox -s build
nox > Running session build
nox > Creating virtual environment (virtualenv) using python3.7 in .nox/build
nox > Command ~/.pyenv/versions/3.9.1/bin/python3 -m virtualenv /Users/stargirl/workspace/blog.thea.codes/.nox/build -p python3.7 failed with exit code 1:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
nox > Session build failed. Nox and Virtualenv are consistent here. So I'm not sure what we should do. We can try to detect pyenv stubs that are inactive and skip those environments, but I wanted to get some clarity on the assertion that virtualenv somehow does things differently that we do. |
What about this example:
$ virtualenv -p python_not_installed env
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python_not_installed'
If
It has this system of plugins that allows for custom logic in interpreter discovery (option |
Virtualenv isn't our only backend, so that's one compelling reason why we do the lookup ourselves.
We can modify Nox to detect pyenv stubs that aren't available and skip those sessions. That should resolve this issue for now.
Sure, it could be, but presently it is not. |
One slightly off-topic question: If an interpreter cannot be found, is there some way to specify a fallback? For example, how could one express the following to This can almost be done by having # noxfile.py
import nox
@nox.session(python=["3.6", "3.7", "3.8"])
def test(session):
session.install(".[test]")
session.run("pytest", "-n", "4")
@nox.session(venv_backend="conda", python=["3.6", "3.7", "3.8"])
def test_conda(session):
session.install(".[test]")
session.run("pytest", "-n", "4") but how can I have the I know that I can just use the Sorry if this is noise and discussed somewhere, but I am still trying to wrap my head arround how this all works. Thanks! |
EDIT: the solution is to activate all installed targeted Python versions in
pyenv
, see #252 (comment).Describe the bug
The shims inserted by
pyenv
into the shell fool thepy.path.local.sysfind()
call made here, and results in Nox not correctly skipping missing interpreters.How to reproduce
pyenv
installed with at least 2 different Python minor versions.noxfile.py
:$ pbpaste > noxfile.py
on macOS, or in the Docker container:$ 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 docsActual behavior
Nox tries to run all versions, and fails. In my case, it fails on 3.6.
Full output:
Extra debugging material
$ pyenv versions
on my machine:$ nox -l
on my machine: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):We could detect that we're running under
pyenv
, and if so only use the result fromsysfind()
if it doesn't containshims
in the path? 🤷♂️(We shouldn't rely on the output of
sysfind
to detect that we're usingpyenv
though, because the.pyenv
shown there is thePYENV_ROOT
, and that is configurable. I'd suggest to make a$ pyenv --version
call instead.)The text was updated successfully, but these errors were encountered: