Skip to content

Commit 7722b7d

Browse files
authored
Merge pull request #2251 from pypa/bugfix/2212-distutils-spawn-race
Fix race in spawn
2 parents 8b45da0 + 8a4bc38 commit 7722b7d

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

changelog.d/2212.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(Distutils) Allow spawn to accept environment. Avoid monkey-patching global state.

setuptools/_distutils/_msvccompiler.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,8 @@ def link(self,
501501
log.debug("skipping %s (up-to-date)", output_filename)
502502

503503
def spawn(self, cmd):
504-
old_path = os.getenv('path')
505-
try:
506-
os.environ['path'] = self._paths
507-
return super().spawn(cmd)
508-
finally:
509-
os.environ['path'] = old_path
504+
env = dict(os.environ, path=self._paths)
505+
return super().spawn(cmd, env=env)
510506

511507
# -- Miscellaneous methods -----------------------------------------
512508
# These are all used by the 'gen_lib_options() function, in

setuptools/_distutils/spawn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
_cfg_target_split = None
2121

2222

23-
def spawn(cmd, search_path=1, verbose=0, dry_run=0):
23+
def spawn(cmd, search_path=1, verbose=0, dry_run=0, env=None):
2424
"""Run another program, specified as a command list 'cmd', in a new process.
2525
2626
'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):
4949
if executable is not None:
5050
cmd[0] = executable
5151

52-
env = None
52+
env = env if env is not None else dict(os.environ)
53+
5354
if sys.platform == 'darwin':
5455
global _cfg_target, _cfg_target_split
5556
if _cfg_target is None:
@@ -68,8 +69,7 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0):
6869
'now "%s" but "%s" during configure'
6970
% (cur_target, _cfg_target))
7071
raise DistutilsPlatformError(my_msg)
71-
env = dict(os.environ,
72-
MACOSX_DEPLOYMENT_TARGET=cur_target)
72+
env.update(MACOSX_DEPLOYMENT_TARGET=cur_target)
7373

7474
try:
7575
proc = subprocess.Popen(cmd, env=env)

0 commit comments

Comments
 (0)