From 360aadc4c2a9941a68a3f3f63375ce5380fef6a0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 Jul 2020 15:31:18 -0400 Subject: [PATCH 1/2] Allow spawn to accept environment. Avoid monkey-patching global state. Closes pypa/setuptools#2212 and closes pypa/distutils#5. --- distutils/_msvccompiler.py | 8 ++------ distutils/spawn.py | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index af8099a407..0e98692e31 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -501,12 +501,8 @@ def link(self, log.debug("skipping %s (up-to-date)", output_filename) def spawn(self, cmd): - old_path = os.getenv('path') - try: - os.environ['path'] = self._paths - return super().spawn(cmd) - finally: - os.environ['path'] = old_path + env = dict(os.environ, path=self._paths) + return super().spawn(cmd, env=env) # -- Miscellaneous methods ----------------------------------------- # These are all used by the 'gen_lib_options() function, in diff --git a/distutils/spawn.py b/distutils/spawn.py index 0d1bd0391e..fc592d4a91 100644 --- a/distutils/spawn.py +++ b/distutils/spawn.py @@ -20,7 +20,7 @@ _cfg_target_split = None -def spawn(cmd, search_path=1, verbose=0, dry_run=0): +def spawn(cmd, search_path=1, verbose=0, dry_run=0, env=None): """Run another program, specified as a command list 'cmd', in a new process. 'cmd' is just the argument list for the new process, ie. @@ -49,7 +49,8 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): if executable is not None: cmd[0] = executable - env = None + env = env if env is not None else dict(os.environ) + if sys.platform == 'darwin': global _cfg_target, _cfg_target_split if _cfg_target is None: @@ -68,8 +69,7 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0): 'now "%s" but "%s" during configure' % (cur_target, _cfg_target)) raise DistutilsPlatformError(my_msg) - env = dict(os.environ, - MACOSX_DEPLOYMENT_TARGET=cur_target) + env.update(MACOSX_DEPLOYMENT_TARGET=cur_target) try: proc = subprocess.Popen(cmd, env=env) From 8a4bc38e7b582b2006e17118162b1d2a0a23b8ad Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 12 Jul 2020 05:02:18 -0400 Subject: [PATCH 2/2] Update changelog. --- changelog.d/2212.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/2212.misc.rst diff --git a/changelog.d/2212.misc.rst b/changelog.d/2212.misc.rst new file mode 100644 index 0000000000..d6fc7bf8af --- /dev/null +++ b/changelog.d/2212.misc.rst @@ -0,0 +1 @@ +(Distutils) Allow spawn to accept environment. Avoid monkey-patching global state.