()
| 203 | |
| 204 | |
| 205 | def _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 | ) |
no test coverage detected