From d300e75a178a567f517a94f0513ad91d3975de5b Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 6 Sep 2019 22:21:25 -0500 Subject: [PATCH] Inherit environment from parent process. --- colcon_core/package_identification/python.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/colcon_core/package_identification/python.py b/colcon_core/package_identification/python.py index c1049ce2..f1d789ac 100644 --- a/colcon_core/package_identification/python.py +++ b/colcon_core/package_identification/python.py @@ -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() @@ -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. @@ -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')