Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47b4514

Browse files
authored
Merge pull request #20650 from charris/backport-20640
BUG: Support env argument in CCompiler.spawn
2 parents dc74976 + a248174 commit 47b4514

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

numpy/distutils/ccompiler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class where more documentation can be found.
109109

110110

111111
# Using customized CCompiler.spawn.
112-
def CCompiler_spawn(self, cmd, display=None):
112+
def CCompiler_spawn(self, cmd, display=None, env=None):
113113
"""
114114
Execute a command in a sub-process.
115115
@@ -120,6 +120,7 @@ def CCompiler_spawn(self, cmd, display=None):
120120
display : str or sequence of str, optional
121121
The text to add to the log file kept by `numpy.distutils`.
122122
If not given, `display` is equal to `cmd`.
123+
env: a dictionary for environment variables, optional
123124
124125
Returns
125126
-------
@@ -131,16 +132,17 @@ def CCompiler_spawn(self, cmd, display=None):
131132
If the command failed, i.e. the exit status was not 0.
132133
133134
"""
135+
env = env if env is not None else dict(os.environ)
134136
if display is None:
135137
display = cmd
136138
if is_sequence(display):
137139
display = ' '.join(list(display))
138140
log.info(display)
139141
try:
140142
if self.verbose:
141-
subprocess.check_output(cmd)
143+
subprocess.check_output(cmd, env=env)
142144
else:
143-
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
145+
subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env)
144146
except subprocess.CalledProcessError as exc:
145147
o = exc.output
146148
s = exc.returncode

0 commit comments

Comments
 (0)