Skip to content

Allow use of venv rather than virtualenv #199

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

Closed
pfmoore opened this issue May 26, 2019 · 12 comments · Fixed by #231
Closed

Allow use of venv rather than virtualenv #199

pfmoore opened this issue May 26, 2019 · 12 comments · Fixed by #231

Comments

@pfmoore
Copy link
Contributor

pfmoore commented May 26, 2019

How would this feature be useful?
Some projects (for example, pipx) have test suites that cannot run under virtualenv, but require venv. Being able to choose whether to use virtualenv or venv would allow using nox to run the test suite.

Describe the solution you'd like
The simplest solution I can think of is to use a parameter to nox.session, something like @nox.session(stdlib_venv=True). But honestly, it doesn't matter much to me how it gets specified.

Describe alternatives you've considered
I can't really think of a good alternative, other than "use something else" :-( Ideally, virtualenv and venv would be sufficiently compatible that it doesn't matter which you use, but that simply doesn't seem to be the case.

@stsewd
Copy link
Collaborator

stsewd commented May 26, 2019

nox is python3 only, so I guess we can just replace virtualenv?

@theacodes
Copy link
Collaborator

theacodes commented May 26, 2019 via email

@pfmoore
Copy link
Contributor Author

pfmoore commented May 26, 2019

... and there are things that only work in virtualenv (there are some nasty interactions if, for example, you create a venv from within a virtualenv). So I definitely think it's something where the user needs to be able to choose. Of course, as someone who wants to ditch Python 2.7 ASAP, my personal preference would be to go venv by default with an option to use virtualenv, but that would be backward incompatible, so I'm fine with venv being the one that needs to be opt-in.

@theacodes
Copy link
Collaborator

Thinking of future-proofing this for conda, pyenv, or pipenv support as well (see #183 #4 #159) we should probably just extend the pattern we have with ProcessEnv and VirtualEnv to include Venv, Conda and PyEnvbackends as well. We could abstract a bit more common code of the currentVirtualEnv` class to make it the base for these new backends.

Session decorator wise, I think it makes the most sense to have something like:

@nox.session(py="3.7", venv_backend="venv")

Thoughts?

@stsewd
Copy link
Collaborator

stsewd commented May 28, 2019

I like the idea of having different backends, shouldn't be this a global option that could be overridden by each session?

@theacodes
Copy link
Collaborator

theacodes commented May 28, 2019 via email

@cs01
Copy link
Contributor

cs01 commented Jul 28, 2019

I'm trying to migrate pipx's test suite to nox right now and am running into this issue.

The problem is the pip executable is pointing to the python nox's virtualenv session rather than one that pipx created with venv:

>> ll /tmp/pipx_tests__fc881ve/subdir/pipxhome/.cache/3d7e26ae000b6c1/bin/python 
lrwxrwxrwx 1 csmith csmith 47 Jul 28 08:42 /tmp/pipx_tests__fc881ve/subdir/pipxhome/.cache/3d7e26ae000b6c1/bin/python -> /home/csmith/git/pipx/.nox/unittests/bin/python

What is the status on adding venv support to nox? I thought I might get lucky and tried venv_backend="venv" 😄 but no luck.

@cs01
Copy link
Contributor

cs01 commented Jul 28, 2019

To my surprise, I changed

        cmd = [sys.executable, "-m", "virtualenv", self.location]

to

        cmd = [sys.executable, "-m", "venv", self.location]

in nox/virtualenv.py and nox still worked. The pipx tests then passed with nox. I'll see if I can put together a PR.

@cs01
Copy link
Contributor

cs01 commented Jul 29, 2019

I hacked something together, but I'll wait for #217 to land before adding the venv backend. There was some additional logic needed to find the correct python interpreter when creating a venv from within one of nox's virtualenv's. The tox-venv project served as a good template to work from.

@theacodes
Copy link
Collaborator

Just merged #217, would love to see your changes! Let me know if you need help.

@theacodes
Copy link
Collaborator

I've assigned this issue to you, @cs01, but definitely holler if you're not okay with that.

@cs01
Copy link
Contributor

cs01 commented Aug 1, 2019

No that's perfect. I think I am in a good spot to be assigned this since I got it working with pipx.

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

Successfully merging a pull request may close this issue.

4 participants