-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Add a venv tool. #1128
Add a venv tool. #1128
Conversation
Commits are reviewable in sequence individually if that suits. |
This is hefty, but also not as big as it looks. Of the +3,371 −49 delta +2,633 comes from embedding the virtualenv.py script for Python 2.7 support. Thanks in advance for your patience on the remaining diff though. |
Going into draft mode while I work out CI failures that do not repro on my machine. |
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.
Thanks!
exclude=(pex_info.internal_cache, pex_builder.BOOTSTRAP_DIR, "__main__.py"), | ||
) | ||
|
||
for dist in pex.activate(): |
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 had thought of "activate" as meaning "add to the pythonpath of the current process", so it's interesting to see it used like this. Would splitting that method into "iterate over what would have been activated" vs "activate" make sense?
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.
That might make sense although it is neither here nor there for tool use where the side-effect of the distributions getting added to the sys.path here has no relevant effect:
https://github.com/pantsbuild/pex/blob/12ad6a63f988c07065cebbfb6aa4102a6d3fa094/pex/environment.py#L476
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 a good deal thornier than it may look. The code paths involved are relevant in the resolve-from-pex work though so I'll defer to that work.
Add a
venv
tool to create a virtual environment from a PEX file. Thevirtual environment is seeded with just the PEX user code and
distributions applicable to the selected interpreter for the local
machine. The virtual environment does not have Pip installed by default
although that can be requested with
--pip
.The virtual environment comes with a
__main__.py
at the root of thevenv to emulate a loose pex that can be run with
python venv.dir
justlike a loose pex. This entry point supports all the behavior of the
original PEX file not related to interpreter selection, namely support
for PEX_SCRIPT, PEX_MODULE, PEX_INTERPRETER and PEX_EXTRA_SYS_PATH.
A sibling
pex
script is linked to__main__.py
to provide themaximum performance entrypoint that always avoids interpreter
re-execing and thus yields equivalent performance to a pure virtual
environment.
Work towards #962 and #1115.