26
26
import warnings
27
27
28
28
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 :
34
38
from distutils .core import Extension
35
39
36
40
import Cython
37
41
from Cython .Build .Inline import _get_build_extension
38
42
from Cython .Build .Dependencies import cythonize
39
43
40
- # GCC detection
41
- import subprocess
42
-
43
44
import numpy as np
44
45
45
46
import pystan .api
@@ -143,11 +144,6 @@ class StanModel:
143
144
Indicates whether intermediate output should be piped to the console.
144
145
This output may be useful for debugging.
145
146
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
-
151
147
kwargs : keyword arguments
152
148
Additional arguments passed to `stanc`.
153
149
@@ -215,7 +211,7 @@ class StanModel:
215
211
def __init__ (self , file = None , charset = 'utf-8' , model_name = "anon_model" ,
216
212
model_code = None , stanc_ret = None , boost_lib = None ,
217
213
eigen_lib = None , verbose = False , obfuscate_model_name = True ,
218
- extra_compile_args = None , compiler = None ):
214
+ extra_compile_args = None ):
219
215
220
216
if stanc_ret is None :
221
217
stanc_ret = pystan .api .stanc (file = file ,
@@ -288,9 +284,6 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
288
284
('BOOST_DISABLE_ASSERTS' , None ),
289
285
]
290
286
291
- # create here to allow compiler injection on Windows
292
- build_extension = _get_build_extension ()
293
-
294
287
# compile stan models with optimization (-O2)
295
288
# (stanc is compiled without optimization (-O0) currently, see #33)
296
289
if extra_compile_args is None :
@@ -300,26 +293,8 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
300
293
'-Wno-unused-function' ,
301
294
'-Wno-uninitialized' ,
302
295
]
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' ]
323
298
324
299
distutils .log .set_verbosity (verbose )
325
300
extension = Extension (name = self .module_name ,
@@ -330,7 +305,7 @@ def __init__(self, file=None, charset='utf-8', model_name="anon_model",
330
305
extra_compile_args = extra_compile_args )
331
306
332
307
cython_include_dirs = ['.' , pystan_dir ]
333
-
308
+ build_extension = _get_build_extension ()
334
309
build_extension .extensions = cythonize ([extension ],
335
310
include_path = cython_include_dirs ,
336
311
quiet = not verbose )
0 commit comments