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

Running with --no-venv causes session.install to use unexpected interpreter #503

Closed
rhoban13 opened this issue Nov 12, 2021 · 7 comments · Fixed by #537
Closed

Running with --no-venv causes session.install to use unexpected interpreter #503

rhoban13 opened this issue Nov 12, 2021 · 7 comments · Fixed by #537
Labels

Comments

@rhoban13
Copy link

Describe the bug
Running with --no-venv causes session.install to be invoked with the python executable found on PATH, not the one running nox.

How to reproduce
Running in an environment where the executables python and python3.8 are distinct:

$ which python python3.8
/usr/bin/python
/usr/bin/python3.8

My noxfile.py just installs pytest. Running we obtain:

$ python3.8 -m nox --no-venv
nox > Running session validate
nox > python -m pip install pytest
nox > Command python -m pip install failed with exit code 1:
/usr/bin/python: No module named pip
nox > Session validate failed.

Ignore the "No module named pip", the point being it's invoking /usr/bin/python, not /usr/bin/python3.8.

Expected behavior
Documentation on forcing-sessions-backend suggests this should run "on the current python interpreter (the one running nox)".

Possible fix
I suspect a fix could be applied in Session.install here to use sys.executable instead of the string `"python". I'm not certain what conditions we'd need to check beforhand (how to verify we aren't running in a venv).

@cjolowicz
Copy link
Collaborator

Thanks for reporting this!

I suspect a fix could be applied in Session.install here to use sys.executable instead of the string `"python". I'm not certain what conditions we'd need to check beforhand (how to verify we aren't running in a venv).

That should work. You can check if self._runner.venv is an instance of PassthroughEnv, as that's the one that implements the --no-venv feature.

@theacodes
Copy link
Collaborator

theacodes commented Nov 13, 2021 via email

@rhoban13
Copy link
Author

I feel like invoking "install" without a virtual environment should be an error, since all sorts of unexpected behavior can happen. If someone wants to actually install something in the global python interpreter, they can run pip install via session.run.

I agree you typically shouldn't install things into the global python interpreter, however that doesn't seem like it should be nox's responsibility to validate. This is basically why pip --require-virtualenv exists, I tend to export PIP_REQUIRE_VIRTUALENV in most setups to check this.

@theacodes
Copy link
Collaborator

theacodes commented Nov 14, 2021 via email

@DiddiLeija
Copy link
Collaborator

Yup, an error message (or even just a warning) would be better than doing pip variable manipulations. If you want, in the next week I can post a PR to do this. We only need to sketch how the message should look like ;)

@cjolowicz
Copy link
Collaborator

cjolowicz commented Nov 15, 2021

I agree that session.install without a venv backend is dangerous, and it would be better to raise a helpful error here. However, this is a breaking change, and there are projects out there that rely on the current behavior (e.g. here and here). This behavior was explicitly allowed in #316, see #318 and #301 for background. Should we go through a deprecation phase then?

@rhoban13
Copy link
Author

#301 is exactly the use case I'm interested in.

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

Successfully merging a pull request may close this issue.

4 participants