File tree 1 file changed +22
-1
lines changed
Filter options
1 file changed +22
-1
lines changed
Original file line number Diff line number Diff line change 16
16
import os
17
17
import subprocess
18
18
import contextlib
19
+ import unittest .mock
19
20
with contextlib .suppress (ImportError ):
20
21
import winreg
21
22
@@ -504,7 +505,27 @@ def link(self,
504
505
505
506
def spawn (self , cmd ):
506
507
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 )
508
529
509
530
# -- Miscellaneous methods -----------------------------------------
510
531
# These are all used by the 'gen_lib_options() function, in
You can’t perform that action at this time.
0 commit comments