Commit 6e92cdab authored by Jason R. Coombs's avatar Jason R. Coombs

Add fallback for the situation where distutils.ccompiler.CCompiler.spawn has...

Add fallback for the situation where distutils.ccompiler.CCompiler.spawn has been patched. Fixes pypa/distutils#15.
parent 37fa0e75
......@@ -16,6 +16,7 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler.
import os
import subprocess
import contextlib
import unittest.mock
with contextlib.suppress(ImportError):
import winreg
......@@ -504,7 +505,27 @@ class MSVCCompiler(CCompiler) :
def spawn(self, cmd):
env = dict(os.environ, PATH=self._paths)
return super().spawn(cmd, env=env)
with self._fallback_spawn(cmd, env) as fallback:
return super().spawn(cmd, env=env)
return fallback.value
@contextlib.contextmanager
def _fallback_spawn(self, cmd, env):
"""
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
so the 'env' kwarg causes a TypeError. Detect this condition and
restore the legacy, unsafe behavior.
"""
bag = type('Bag', (), {})()
try:
yield bag
except TypeError as exc:
if "unexpected keyword argument 'env'" not in str(exc):
raise
else:
return
with unittest.mock.patch('os.environ', env):
bag.value = super().spawn(cmd)
# -- Miscellaneous methods -----------------------------------------
# These are all used by the 'gen_lib_options() function, in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment