Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit b71cf1c

Browse files
authored
Remove gcc injection
Removes the gcc injection code. User needs to define `distutils.cfg` file with `[compiler]\nmingw32` to use gcc. Uses `distutils.ccompiler.get_default_compiler()` to see if `msvc` or `mingw32` is used.
1 parent fc5dbef commit b71cf1c

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

pystan/model.py

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@
2626
import warnings
2727

2828
import distutils
29-
30-
try:
31-
# MSVC 2017 support (setuptools >= 34.4.0)
32-
from setuptools import Extension
33-
except ImportError:
29+
from distutils import ccompiler
30+
31+
if ccompiler.get_default_compiler() == 'msvc':
32+
try:
33+
# MSVC 2017 support (setuptools >= 34.4.0)
34+
from setuptools import Extension
35+
except ImportError:
36+
from distutils.core import Extension
37+
else:
3438
from distutils.core import Extension
3539

3640
import Cython
3741
from Cython.Build.Inline import _get_build_extension
3842
from Cython.Build.Dependencies import cythonize
3943

40-
# GCC detection
41-
import subprocess
42-
4344
import numpy as np
4445

4546
import pystan.api
@@ -143,11 +144,6 @@ class StanModel:
143144
Indicates whether intermediate output should be piped to the console.
144145
This output may be useful for debugging.
145146
146-
compiler : string, None by default
147-
Only for Windows. Choose compiler type.
148-
- for GCC use 'gcc' or 'mingw32',
149-
- for Microsoft Visual C++ use 'msvc'
150-
151147
kwargs : keyword arguments
152148
Additional arguments passed to `stanc`.
153149
@@ -215,7 +211,7 @@ class StanModel:
215211
def __init__(self, file=None, charset='utf-8', model_name="anon_model",
216212
model_code=None, stanc_ret=None, boost_lib=None,
217213
eigen_lib=None, verbose=False, obfuscate_model_name=True,
218-
extra_compile_args=None, compiler=None):
214+
extra_compile_args=None):
219215

220216
if stanc_ret is None:
221217
stanc_ret = pystan.api.stanc(file=file,
@@ -288,9 +284,6 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
288284
('BOOST_DISABLE_ASSERTS', None),
289285
]
290286

291-
# create here to allow compiler injection on Windows
292-
build_extension = _get_build_extension()
293-
294287
# compile stan models with optimization (-O2)
295288
# (stanc is compiled without optimization (-O0) currently, see #33)
296289
if extra_compile_args is None:
@@ -300,26 +293,8 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
300293
'-Wno-unused-function',
301294
'-Wno-uninitialized',
302295
]
303-
if platform.platform().startswith('Win'):
304-
# sanitize input
305-
if compiler == 'gcc':
306-
compiler = 'mingw32'
307-
# inject the compiler kw
308-
if compiler is not None:
309-
build_extension.compiler = compiler
310-
# inject gcc (mingw32) if found else use msvc
311-
elif build_extension.compiler is None:
312-
# run subprocess without output
313-
with open(os.devnull, 'w') as DEVNULL:
314-
try:
315-
subprocess.call(["gcc", "--version"], stdout=DEVNULL)
316-
except FileNotFoundError:
317-
build_extension.compiler = "msvc"
318-
else:
319-
build_extension.compiler = "mingw32"
320-
321-
if build_extension.compiler == "msvc":
322-
extra_compile_args = ['/EHsc', '-DBOOST_DATE_TIME_NO_LIB']
296+
if platform.platform().startswith('Win') and ccompiler.get_default_compiler() == 'msvc':
297+
extra_compile_args = ['/EHsc', '-DBOOST_DATE_TIME_NO_LIB']
323298

324299
distutils.log.set_verbosity(verbose)
325300
extension = Extension(name=self.module_name,
@@ -330,7 +305,7 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
330305
extra_compile_args=extra_compile_args)
331306

332307
cython_include_dirs = ['.', pystan_dir]
333-
308+
build_extension = _get_build_extension()
334309
build_extension.extensions = cythonize([extension],
335310
include_path=cython_include_dirs,
336311
quiet=not verbose)

0 commit comments

Comments
 (0)