MCPcopy Create free account
hub / github.com/numpy/numpy / _get_compiler_status

Function _get_compiler_status

numpy/f2py/tests/util.py:205–264  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

203
204
205def _get_compiler_status():
206 global _compiler_status
207 if _compiler_status is not None:
208 return _compiler_status
209
210 _compiler_status = (False, False, False)
211 if IS_WASM:
212 # Can't run compiler from inside WASM.
213 return _compiler_status
214
215 # XXX: this is really ugly. But I don't know how to invoke Distutils
216 # in a safer way...
217 code = textwrap.dedent(f"""\
218 import os
219 import sys
220 sys.path = {repr(sys.path)}
221
222 def configuration(parent_name='',top_path=None):
223 global config
224 from numpy.distutils.misc_util import Configuration
225 config = Configuration('', parent_name, top_path)
226 return config
227
228 from numpy.distutils.core import setup
229 setup(configuration=configuration)
230
231 config_cmd = config.get_config_cmd()
232 have_c = config_cmd.try_compile('void foo() {{}}')
233 print('COMPILERS:%%d,%%d,%%d' %% (have_c,
234 config.have_f77c(),
235 config.have_f90c()))
236 sys.exit(99)
237 """)
238 code = code % dict(syspath=repr(sys.path))
239
240 tmpdir = tempfile.mkdtemp()
241 try:
242 script = os.path.join(tmpdir, "setup.py")
243
244 with open(script, "w") as f:
245 f.write(code)
246
247 cmd = [sys.executable, "setup.py", "config"]
248 p = subprocess.Popen(cmd,
249 stdout=subprocess.PIPE,
250 stderr=subprocess.STDOUT,
251 cwd=tmpdir)
252 out, err = p.communicate()
253 finally:
254 shutil.rmtree(tmpdir)
255
256 m = re.search(br"COMPILERS:(\d+),(\d+),(\d+)", out)
257 if m:
258 _compiler_status = (
259 bool(int(m.group(1))),
260 bool(int(m.group(2))),
261 bool(int(m.group(3))),
262 )

Callers 3

has_c_compilerFunction · 0.85
has_f77_compilerFunction · 0.85
has_f90_compilerFunction · 0.85

Calls 3

openFunction · 0.85
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected