Skip to content

Commit

Permalink
Inherit environment from parent process.
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Sep 7, 2019
1 parent 1cf7b4f commit d300e75
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions colcon_core/package_identification/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ def get_setup_result(setup_py, *, env: Optional[dict]):
:return: Dictionary of data describing the package.
:raise: RuntimeError if the setup script encountered an error
"""
env_copy = os.environ.copy()
if env is not None:
env_copy.update(env)

conn_recv, conn_send = multiprocessing.Pipe(duplex=False)
with conn_send:
p = multiprocessing.Process(
target=_get_setup_result_target,
args=(os.path.abspath(str(setup_py)), env, conn_send)
args=(os.path.abspath(str(setup_py)), env_copy, conn_send),
)
p.start()
p.join()
Expand All @@ -118,7 +122,7 @@ def get_setup_result(setup_py, *, env: Optional[dict]):
.format(setup_py, result_or_exception_string))


def _get_setup_result_target(setup_py: str, env: Optional[dict], conn_send):
def _get_setup_result_target(setup_py: str, env: dict, conn_send):
"""
Run setup.py in a modified environment.
Expand All @@ -136,11 +140,8 @@ def _get_setup_result_target(setup_py: str, env: Optional[dict], conn_send):
# need to be in setup.py's parent dir to detect any setup.cfg
os.chdir(os.path.dirname(setup_py))

# don't worry - the environments of functions called with
# subprocess.Process don't leak into each other
os.environ.clear()
if env is not None:
os.environ.update(env)
os.environ.update(env)

result = distutils.core.run_setup(
str(setup_py), ('--dry-run',), stop_after='config')
Expand Down

0 comments on commit d300e75

Please sign in to comment.