-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[RFC] The next generation of virtualenv #1366
Comments
An ambitious proposal!
Consider using appdirs (or similar) to discover configuration in platform-preferred locations. |
appdirs well could be an option, though then we'd need to start the business of vendoring stuff into our package. To be fair 70% of this is already done, would just need a better reorganization. |
Why vendor rather than just depending on it? (Not that it's hard to vendor, it's just a single file). IMO, we really need to accept that (with the notable exception of pip) packaging tools really should be built just like any other application. If having dependencies is sufficiently hard that PyPA apps avoid them, what does that say about how well we're doing making it easy for our users to develop applications? (Sorry, not making some sort of big point about virtualenv here, I just see so many people saying "adding a PyPI dependency isn't a big deal", then the PyPA tools I work on vendoring stuff makes me wonder...). |
Without vendoring the cross interpreter feature will be hard I think. E.g. creating a virtual environment for an interpreter not having virtualenv installed. |
Uh, this would mean that we can't depend on any additional packages from virtualenv. Since we will provide a zipapp, what usecases does this enable? |
@gaborbernat You mean the From @pradyunsg:
Actually, as @gaborbernat said, the |
Hmm... My worry here is that the network effects of this might cause slowdown of adoption of newer versions of Python and the combinational explosion of number of supported Pythons. CPython is discussing different release cadence for 3.9, so 2 years might even be longer than what some releases might have from core devs. That said, I don't want to be blocking this but mostly just making sure I voice that I'm not keen on doing this.
Definitely. @gaborbernat probably knows I'd say this -- these would be good to have but I'm pretty sure folks who are more familiar with the implementation would be best positioned to do this. At the very least, in terms of support in the long term, and ideally, also the work of getting it well supported in the first place (CI, tests, etc).
I'm biased -- I'd really like to see this be TOML instead. :) (I have not completely processed this yet since I have to go somewhere -- but this does look like a great overall goal!) |
we already can't really depend on additional packages because of the cross interpreter feature, so I don't consider this as a major drawback, and I would like to have a simple no install/dependency way of running virtual environments (needed when people invoke us from node packages). Given it does not cost us much offering besides zipapp seems cheap. |
I'm not sure I understand the rationale for this. It seems like it will make the maintenance of |
FWIW I think using the built in Virtualenv also wouldn't need to monkeypatch anything, it would just use the public API which should be fine. FWIW I would recommend checking my old rewrite virtualenv branch, it did a lot of these things already. |
I would probably suggest a plugin system isn't super useful for virtualenv though, at most there's likely to just be one hook, a post create step and even then you can probably get away just having a list of things to install. |
ALSO, you can still depend on stuff "naturally" and still use zipapps, you just have to vendor inside the zipapp itself. I would recommend moving away from the re-execute under target python option, it is a bad thing and can be done much cleaner. |
OTOH, we probably shouldn't be doing this anyway -- https://www.python.org/dev/peps/pep-0427/#is-it-possible-to-import-python-code-directly-from-a-wheel-file |
@pradyunsg so any other methods for bootstrapping pip without putting the wheel on the path? |
Bootstrapping pip is probably OK - it's what virtualenv uses now1. But I'd strongly recommend only using it for pip, and not as a means of running virtualenv itself. 1 But I'd avoid any complicated functionality - using a wheel on PATH to install pip from that wheel is pretty much guaranteed to be OK. But you might have issues if you, for example, access the internet using such a wheel, as I think certifi needs its embedded certificate bundle as an actual file (but I may be wrong, that's never caused me a problem, but I know |
Any reason why we don't ship pip as |
@gaborbernat have you tried it? does it work? if the approach you outlined works on windows I don't have any initial concerns but @uranusjr likely would have feedback. My only comments are in line with @dstuff which is to say -- simpler is better |
Because in certain cases, pip won't run direct from a zipfile (or a wheel, it's the same thing), as I said above. 99% (alert - made up number) of the time, it works, but sometimes the fact that the certificate bundle needs to be a real file matters. It would probably work fine to bundle pip as a shiv though, as shiv unpacks the zipapp before running it, precisely to avoid the corner cases where running from a zip breaks. Nobody to my knowledge has tried it, though. As usual, the main reasons it hasn't happened are:
|
I don't think we need that here -- virtualenv is using the pip wheel to install from itself IIRC, which should work fine. As @pfmoore said, the only "extra" thing that get-pip.py does is unpack the certificates and provide a path to them. Since virtualenv's usecase won't hit the network, we don't need to do anything new here.
This, much more than the others IMO. We could but there's more impactful issues to tackle. :) |
I had a PR at one point that built pip as a zip app, it worked but IIRC I had to make changes to pip to make it fully functional. |
That might be complicated a slight bit now since pip does invoke itself as a subprocess of itself for PEP 517. I'm not sure but that's definitely worth exploring. |
At this point shiv (or another self-extracting option) would be more suitable for pip than trying to work pip into zip-runnable. But I don’t think this is a particularly important thing at this point. ensurepip already goes the wheel-on-path route, why not just do the same. Alternative pip bootstrapping can be explored after we fry all the bigger fishes, and potentially be contributed back to stdlib. |
Sounds like a plan [one that we're following already. ;)] |
Thanks for the links, based on feedback I've started some initial work over at https://github.com/gaborbernat/virtualenv/tree/rewrite/src/virtualenv. The plan is to get it into a release shape within the next month (and have a week of open review before that). Based on the impact of the change, I plan to make it release |
+1 for using venv if it exists. That would make PyPy's use case simpler. |
So the rewrite got to a state where I feel comfortable people having a look over it and giving some feedback. Please reach out to me if you have some free time to help with this; the plan is to have it be released by end of month 🤞 Note https://github.com/pypa/virtualenv/milestone/7 still need to be implemented, however, the core idea is there. PS. Created a feedback PR under #1481 |
Feature request: Provide a mechanism for defining custom environment variables, for instance by placing a
|
I don't think I understand your use case? How would these environment variables be used, set, when? Edit. NM. I see you expanded on #1124. |
A small update; I've managed to close most blocking issues, other than two which still need some love: testing include headers + caching python interrogation calls with some lock applied over the app data, so we can create virtual environments in parallel (to different locations). At the current pace I might be a few day late... but definitely should be out by 7th February. |
What's our plan in terms of the rollout? Would we have a beta released prior to the main release? |
Yeah, want to get something out Monday... And then leave tentatively a week for feedback, fixes... And then replace master with rewrite and release. |
I'm not 100% sure that a week would be enough and we should definitely communicate across multiple channels that we want folks to try out the beta. |
The keyword there was tentatively. I'm optimistic here, given the amount of effort I've put in I'm not expecting major issues, but 🤷♂ |
As the beta is out, I feel this issue served is the purpose. I'll close and we can discuss more focused on dedicated issues. |
Following the discussion in 1362 it became apparent that for virtualenv to be able to support the new world (Windows Store installs, venv interpreters) we need some major change of direction.
Here's my proposal for going ahead with this project. This will be a major refactor for the project, that plans to keep existing interface compatibility though.
Project goal
Planned features
universal pypi wheel,
cross-platform - Windows, all UNIX flavours, MacOS.
support for most supported pythons, the initial pool of supported Python version:
python2.7
,python3.4
,python3.5
,python3.5
,pypy3
,pypy2
(hoping for IronPython and Jython at some point - any other ones we should support?)A two year grace period of support: our interface will keep the interpreter support for two more years past its EOL: creating virtual environments is so basic that this package is the last one that should drop compatibility. During this transitional two years period, we guarantee bug fixes and compatibility. New feature support is a best effort though.
ability to specify the target python (we'll use PEP-514/PEP-394/explicit link to discover these versions) and create virtual environments even if that target does not have this package installed
prefer built-in venv: if the target python has venv we'll create the environment using that (and then perform subsequent operations on that to facilitate other guarantees we offer)
ability to provision seed packages (after the creation of the virtual environments this packages will be already installed):
pip
,setuptools
andwheel
are the seed packages (these packages are also automatically injected as offline wheel packages)interfaces:
python -m virtualenv
,virtualenv
)PYTHONPATH=/t/path/to/virtualenv.whl python -m virtualenv
) - universal wheel,import virtualenv; virtualenv.create("target")
shell support - activation/deactivation scripts and prompt environment variables - by default we generate:
three-layered configuration system, each option is determined as follows:
VIRTUALENV_
prefix,plugin system these are extension points the user can inject their own custom logic, and generate an extended version of virtualenv (current bootstrapping logic):
virtualenv support - the operation should work even if the invoking python is a virtualenv created python,
venv support - the operation should work even if the invoking python is a virtualenv created python,
relocatable environments: an environment should keep working as long as the root python is not removed from the OS (e.g. renaming the root environment folder should not break things).
Difference from stdlib venv
How we differ from the standard library venv? The virtualenv package plans to be:
In general, offer features that other downstream tools (for example tox, pre-commit, pipenv, pipsi, pipx) who need virtual environments as an API would want.
PyPy members (and the public please too) share your thoughts or plus one if you agree. @pfmoore @dstufft @di @pradyunsg @cjerdonek @ncoghlan @jaraco @techalchemy @uranusjr @pganssle @benoit-pierre @dholth @lkollar @takluyver @zooba
The text was updated successfully, but these errors were encountered: