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

Fix setting of PEX_PATH in ./pants run (v2 backend) #4969

Merged
merged 11 commits into from
Oct 18, 2017

Conversation

CMLivingston
Copy link
Contributor

@CMLivingston CMLivingston commented Oct 12, 2017

Problem

App servers that need to re-execute (apps watching for file systems changes, jupyter notebooks, etc.) throw an ImportError when being ran with ./pants run because the pants runner pex is losing context of where to find the requirements pex, the sources pex, and any other pexes to merge into the runtime environment. This context is encapsulated in a search path called PEX_PATH, which is being loaded into the PEX_PATH environment variable and is consequently scrubbed out of the environment upon re-exec by pex internal logic.

Solution

Completely remove any setting of PEX_PATH in the environment upon construction of the pants runner pex and instead pass this extra pex path information to the pex_info metadata that is used by the PEXBuilder object to construct the pants runner pex.

Result

Applications that need to re-execute will now be able to locate the sources module and entry point because the search path to resolve them (PEX_PATH) will be persisted in the pants runner pex's PEX-INFO metadata.

Chris Livingston added 2 commits October 12, 2017 12:20
@@ -130,6 +119,9 @@ def create_pex(self, pex_info=None):

extra_pex_paths = [pex.path() for pex in pexes if pex]

if extra_pex_paths:
pex_info.pex_path = ':'.join(extra_pex_paths)
Copy link
Member

Choose a reason for hiding this comment

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

how about using the new PexInfo.merge_pex_path() method here instead of the if + set?


def run(self, *args, **kwargs):
kwargs_copy = copy(kwargs)
env = copy(kwargs_copy.get('env')) if 'env' in kwargs_copy else {}
env[self._PEX_PATH_ENV_VAR_NAME] = self._pex_path()
kwargs_copy['env'] = env
return self._pex.run(*args, **kwargs_copy)
Copy link
Member

Choose a reason for hiding this comment

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

the only reason I can see to do all of the kwargs + env copying here would be to mutate that - so I'm thinking that's probably no longer necessary?

i.e. return self._pex.run(*args, **kwargs) is probably a sufficient method body.

return self._pex.run(*args, **kwargs_copy)

def _pex_path(self):
return ':'.join(self._extra_pex_paths)
Copy link
Member

Choose a reason for hiding this comment

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

seems like this was the last usage of self._extra_pex_paths in this class, so that should probably get yanked from __init__'s kwargs, docstring and body.

@@ -130,6 +116,9 @@ def create_pex(self, pex_info=None):

extra_pex_paths = [pex.path() for pex in pexes if pex]

if extra_pex_paths:
pex_info.merge_pex_path(':'.join(extra_pex_paths))

with safe_concurrent_creation(path) as safe_path:
builder = PEXBuilder(safe_path, interpreter, pex_info=pex_info)
builder.freeze()
Copy link
Member

Choose a reason for hiding this comment

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

also seems like you no longer need the extra_pex_paths_file_path handling down below (lines 126-133) both inside and outside the invalidated block, since WrappedPex no longer does anything with that and it should all be written directly into the pex/chroot's PEX-INFO.

@@ -130,16 +114,11 @@ def create_pex(self, pex_info=None):

Copy link
Member

Choose a reason for hiding this comment

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

can kill this unused line above (line 95):

extra_pex_paths_file_path = path + '.extra_pex_paths'

Copy link
Member

@kwlzn kwlzn left a comment

Choose a reason for hiding this comment

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

lgtm!

@kwlzn
Copy link
Member

kwlzn commented Oct 13, 2017

return '{env_var_name}={pex_path} {cmdline}'.format(env_var_name=self._PEX_PATH_ENV_VAR_NAME,
pex_path=pex_path,
cmdline=cmdline)
return '{env_var_name}={pex_path} {cmdline}'.format(env_var_name=self._PEX_PATH_ENV_VAR_NAME,
Copy link
Member

Choose a reason for hiding this comment

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

bad indent here.

@@ -53,7 +53,7 @@ def cmdline(self, args=()):
cmdline = ' '.join(self._pex.cmdline(args))
pex_path = self._pex_path()
if pex_path:
return '{env_var_name}={pex_path} {cmdline}'.format(env_var_name=self._PEX_PATH_ENV_VAR_NAME,
return '{env_var_name}={pex_path} {cmdline}'.format(env_var_name=self._PEX_PATH_ENV_VAR_NAME,
pex_path=pex_path,
cmdline=cmdline)
Copy link
Member

Choose a reason for hiding this comment

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

these hanging lines should align to the parent too.

Chris Livingston added 2 commits October 17, 2017 14:33
@kwlzn kwlzn merged commit 2180a3d into pantsbuild:master Oct 18, 2017
@kwlzn
Copy link
Member

kwlzn commented Oct 18, 2017

merging on green CI mod the jdk8 failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants