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 race in spawn #2251

Merged
merged 4 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2212.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Distutils) Allow spawn to accept environment. Avoid monkey-patching global state.
8 changes: 2 additions & 6 deletions setuptools/_distutils/_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions setuptools/_distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down