Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e92cda

Browse filesBrowse files
committed
Add fallback for the situation where distutils.ccompiler.CCompiler.spawn has been patched. Fixes #15.
1 parent 37fa0e7 commit 6e92cda
Copy full SHA for 6e92cda

File tree

1 file changed

+22
-1
lines changed
Filter options

1 file changed

+22
-1
lines changed

‎distutils/_msvccompiler.py

Copy file name to clipboardExpand all lines: distutils/_msvccompiler.py
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import subprocess
1818
import contextlib
19+
import unittest.mock
1920
with contextlib.suppress(ImportError):
2021
import winreg
2122

@@ -504,7 +505,27 @@ def link(self,
504505

505506
def spawn(self, cmd):
506507
env = dict(os.environ, PATH=self._paths)
507-
return super().spawn(cmd, env=env)
508+
with self._fallback_spawn(cmd, env) as fallback:
509+
return super().spawn(cmd, env=env)
510+
return fallback.value
511+
512+
@contextlib.contextmanager
513+
def _fallback_spawn(self, cmd, env):
514+
"""
515+
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
516+
so the 'env' kwarg causes a TypeError. Detect this condition and
517+
restore the legacy, unsafe behavior.
518+
"""
519+
bag = type('Bag', (), {})()
520+
try:
521+
yield bag
522+
except TypeError as exc:
523+
if "unexpected keyword argument 'env'" not in str(exc):
524+
raise
525+
else:
526+
return
527+
with unittest.mock.patch('os.environ', env):
528+
bag.value = super().spawn(cmd)
508529

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.