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

Support a --venv mode similar to --unzip mode. #1153

Merged
merged 6 commits into from
Dec 24, 2020

Conversation

jsirois
Copy link
Member

@jsirois jsirois commented Dec 21, 2020

The new --venv execution mode builds a PEX file that includes pex.tools
and extracts itself into a venv under PEX_ROOT upon 1st execution or any
execution that might select a diffrent interpreter than the default.

In order to speed up the local build and execute case, --seed mode is
added to seed the PEX_ROOT caches that will be used at runtime. This is
important for --venv mode since venv seeding depends on the selected
interpreter and one is already selected during the PEX file build
process.

Fixes #962
Fixes #1097
Fixes #1115

@jsirois jsirois force-pushed the venv/execution_mode branch 2 times, most recently from b899f74 to b5309a6 Compare December 22, 2020 22:37
The new --venv execution mode builds a PEX file that includes pex.tools
and extracts itself into a venv under PEX_ROOT upon 1st execution or any
execution that might select a diffrent interpreter than the default.

In order to speed up the local build and execute case, --seed mode is
added to seed the PEX_ROOT caches that will be used at runtime. This is
important for --venv mode since venv seeding depends on the selected
interpreter and one is already selected during the PEX file build
process.
@jsirois jsirois force-pushed the venv/execution_mode branch from b5309a6 to d8df335 Compare December 22, 2020 22:42
@jsirois jsirois changed the title Venv/execution mode Support a --venv mode similar to --unzip mode. Dec 22, 2020
@jsirois jsirois marked this pull request as ready for review December 22, 2020 22:45
@jsirois jsirois force-pushed the venv/execution_mode branch from ce11a7e to 1f40124 Compare December 22, 2020 23:14
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

pex/bin/pex.py Outdated Show resolved Hide resolved
pex/bin/pex.py Outdated Show resolved Hide resolved
pex/tools/commands/venv.py Show resolved Hide resolved
pex/tools/commands/venv.py Outdated Show resolved Hide resolved
pex/tools/commands/venv.py Show resolved Hide resolved
from __future__ import absolute_import


class BinPath(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks similar to Enum - once we drop Py2, would we want to switch this to that? If so, a TODO would be great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should go to enum as should InheritPath. This just moved out of pex.tools.commands.venv so I'll leave as-is. There are alot of things that can change once we drop Python 2.7 including namedtuple -> dataclass and more. That will be a whole project.

pex/variables.py Outdated Show resolved Hide resolved
fallback, # type: _P
):
# type: (...) -> _P
"""Return the value of this property without the default value applied or else the fallback.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, this is without the default? That's not a typo?

If so, perhaps:

Return the value of this property, without the default value applied, and falling back to fallback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. I do not see how the new words make things more clear.

Copy link

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

pex/bin/pex.py Show resolved Hide resolved
pex/interpreter.py Outdated Show resolved Hide resolved
pex/pex_builder.py Show resolved Hide resolved
pex/tools/commands/venv.py Show resolved Hide resolved
pex/tools/commands/venv.py Show resolved Hide resolved
Comment on lines +245 to +255
""".format(
venv_python=venv_python,
venv_bin_dir=venv_bin_dir,
venv_dir=venv_dir,
bin_path=bin_path,
entry_point=pex_info.entry_point,
exec_ast=(
"exec ast in globals_map, locals_map"
if venv.interpreter.version[0] == 2
else "exec(ast, globals_map, locals_map)"
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not worth it yet, but if all of the templated variables are strings, you might consider extracting this as a "real" Python file to allow for mypy/linting, and then loading the file as a resource to template it using a slightly heavier template syntax (something like mustache, but cheaper hopefully).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth it down the line as with the venv __main__.py and the PythonInterpreter identification code, etc...

pex/tools/commands/virtualenv.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants