-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Improve PEX_PATH handling in pex.py #421
Changes from 6 commits
6c5ed74
3a563f4
999c6bf
19fb285
4db4ea4
fbbaf91
aed5211
df5f4f4
c663b40
69bb04a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,11 +68,16 @@ def _activate(self): | |
|
||
# set up the local .pex environment | ||
pex_info = self._pex_info.copy() | ||
combined_pex_paths = [pex_info.pex_path, self._vars.PEX_PATH] | ||
pex_info.update(self._pex_info_overrides) | ||
pex_info.pex_path = ':'.join(filter(None, combined_pex_paths)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure it makes more sense to use a temp var here rather than construct a new pex info API to preserve the overrides where we want pex_info vars overwritten. Doing something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the implementation would look approximately like this:
bonus points if you provide a flag on |
||
self._envs.append(PEXEnvironment(self._pex, pex_info)) | ||
|
||
# N.B. by this point, `pex_info.pex_path` will contain a single pex path | ||
# merged from pex_path in `PEX-INFO` and `PEX_PATH` set in the environment. | ||
# `PEX_PATH` entries written into `PEX-INFO` take precedence over those set | ||
# in the environment. | ||
if pex_info.pex_path: | ||
# set up other environments as specified in PEX_PATH | ||
# set up other environments as specified in pex_path | ||
for pex_path in filter(None, pex_info.pex_path.split(os.pathsep)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about instead of assigning to temp vars and then joining + mutating also, would it make more sense to use e.g.
|
||
pex_info = PexInfo.from_pex(pex_path) | ||
pex_info.update(self._pex_info_overrides) | ||
|
@@ -132,7 +137,7 @@ def _get_site_packages(): | |
def site_libs(cls): | ||
site_libs = cls._get_site_packages() | ||
site_libs.update([sysconfig.get_python_lib(plat_specific=False), | ||
sysconfig.get_python_lib(plat_specific=True)]) | ||
sysconfig.get_python_lib(plat_specific=True)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unintentional re-indent? |
||
# On windows getsitepackages() returns the python stdlib too. | ||
if sys.prefix in site_libs: | ||
site_libs.remove(sys.prefix) | ||
|
@@ -276,10 +281,10 @@ def patch_all(path, path_importer_cache, modules): | |
patch_dict(sys.modules, modules) | ||
|
||
old_sys_path, old_sys_path_importer_cache, old_sys_modules = ( | ||
sys.path[:], sys.path_importer_cache.copy(), sys.modules.copy()) | ||
sys.path[:], sys.path_importer_cache.copy(), sys.modules.copy()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unintentional re-indent? |
||
new_sys_path, new_sys_path_importer_cache, new_sys_modules = self.minimum_sys(inherit_path) | ||
|
||
new_sys_path.extend(filter(None, self._vars.PEX_PATH.split(os.pathsep))) | ||
new_sys_path.extend(self._merge_split(self._pex_info.pex_path, self._vars.PEX_PATH)) | ||
|
||
patch_all(new_sys_path, new_sys_path_importer_cache, new_sys_modules) | ||
yield | ||
|
@@ -490,6 +495,10 @@ def cmdline(self, args=()): | |
cmds.extend(args) | ||
return cmds | ||
|
||
def _merge_split(self, *paths): | ||
filtered_paths = filter(None, paths) | ||
return [p for p in ':'.join(filtered_paths).split(':') if p] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could reduce this to a one liner list comprehension:
with the |
||
def run(self, args=(), with_chroot=False, blocking=True, setsid=False, **kwargs): | ||
"""Run the PythonEnvironment in an interpreter in a subprocess. | ||
|
||
|
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 assume that you found that this
pex_info.update()
call does not actually combine env vars + PEX-INFO, but instead clobbers one or the other?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.
Yup! Env vars clobber the existing vars set by pex info.