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
produce a virtualenv zipapp #1287
Conversation
I like this approach a lot. Distributing virtualenv as a standalone pyz file that can be run with any Python interpreter sounds like a much better approach. From what I can tell, the pyz file will still support the There are a lot of projects that depend on virtualenv that likely expect it to be installed (tox, pew, pipenv, ...) - otherwise, I'd be in favour of making this the official distribution method for virtualenv. It may be worth reaching out to those projects to see how hard it would be for them to switch from needing an installed virtualenv, to simply needing a virtualenv command available. |
The main impediment Paul for tox e.g. is that while one can guarantee virtualenv exist via install requires, one cannot do the same for pyz. This method would only work if downstream tools themselves would be pyz, however one downside of doing so is that no direct command to the tool is available, but rather someone needs to pass the pyz to the interpreter. Therefore I would say not viable. asottile please add some tests for this so we can validate it works for all flavours of python. |
@gaborbernat Thanks for the clarification on tox's position. I thought something like that would be the issue. I've done some work bundling various tools, including tox and virtualenv, as zipapps using shiv. It needs a little fiddling to ensure that the unbundled zipapp is on I'd still like to see the pyz form as a supported approach, even if only as an additional option. |
Yeah, 😁 agreed. later on tox could look into pyz/shiva/pex as well. Some people requested and we accepted to distribute it e.g. via docker too. |
I've written some tests, re-enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach. The tests need some tweaking though, documentation extended, and I feel like we should avoid unwrapping the support files at every invocation and instead have a cache dir.
# Probably some boot script; just in case virtualenv is installed... | ||
@contextlib.contextmanager | ||
def virtualenv_support_dirs(): | ||
"""Context manager yielding either [virtualenv_support_dir] or []""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe more accurate to say: locate virtualenv support files directory
coincidentally, this branch also fixes: PYTHONPATH=virtualenv-16.2.0-py2.py3-none-any.whl python -m virtualenv venv |
virtualenv.py
Outdated
from urllib.parse import urljoin | ||
from urllib.request import pathname2url | ||
with search_dirs_context() as search_dirs: | ||
wheels = find_wheels(["setuptools", "pip"], search_dirs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this generates a long diff because of the indent, what if we would just extract the indented part into its own function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I suggested viewing the diff with ?w=1
in this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Granted that works as a bypass, though would we move this into a sub-function we could avoid changing the lines altogether, not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they'd still change because I'd have to move them -- plus it would increase the api surface of virtualenv (as far as I can tell this function isn't a documented interface but I've found a bunch of calls to it on github >.<)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if you move it to a private function, right after this function. The private function call would be an insert and everything below would be all is same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not add lines for no reason, what's the problem with the indent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep this open then until I get to polish it myself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now only if we can fix #1291 👍
this "works" -- I would like some feedback on the approach however: