26
26
from typing import TYPE_CHECKING , Protocol , cast
27
27
28
28
import numpy as np
29
- from setuptools ._distutils .sysconfig import (
30
- get_config_h_filename ,
31
- get_config_var ,
32
- get_python_inc ,
33
- get_python_lib ,
34
- )
35
29
36
30
# we will abuse the lockfile mechanism when reading and writing the registry
37
31
from pytensor .compile .compilelock import lock_ctx
38
32
from pytensor .configdefaults import config , gcc_version_str
39
33
from pytensor .configparser import BoolParam , StrParam
40
34
from pytensor .graph .op import Op
41
- from pytensor .link .c .exceptions import CompileError , MissingGXX
42
35
from pytensor .utils import (
43
36
LOCAL_BITWIDTH ,
44
37
flatten ,
@@ -266,6 +259,8 @@ def list_code(self, ofile=sys.stdout):
266
259
267
260
def _get_ext_suffix ():
268
261
"""Get the suffix for compiled extensions"""
262
+ from setuptools ._distutils .sysconfig import get_config_var
263
+
269
264
dist_suffix = get_config_var ("EXT_SUFFIX" )
270
265
if dist_suffix is None :
271
266
dist_suffix = get_config_var ("SO" )
@@ -1697,6 +1692,8 @@ def get_gcc_shared_library_arg():
1697
1692
1698
1693
1699
1694
def std_include_dirs ():
1695
+ from setuptools ._distutils .sysconfig import get_python_inc
1696
+
1700
1697
numpy_inc_dirs = [np .get_include ()]
1701
1698
py_inc = get_python_inc ()
1702
1699
py_plat_spec_inc = get_python_inc (plat_specific = True )
@@ -1709,6 +1706,12 @@ def std_include_dirs():
1709
1706
1710
1707
@is_StdLibDirsAndLibsType
1711
1708
def std_lib_dirs_and_libs () -> tuple [list [str ], ...] | None :
1709
+ from setuptools ._distutils .sysconfig import (
1710
+ get_config_var ,
1711
+ get_python_inc ,
1712
+ get_python_lib ,
1713
+ )
1714
+
1712
1715
# We cache the results as on Windows, this trigger file access and
1713
1716
# this method is called many times.
1714
1717
if std_lib_dirs_and_libs .data is not None :
@@ -2388,23 +2391,6 @@ def join_options(init_part):
2388
2391
# xcode's version.
2389
2392
cxxflags .append ("-ld64" )
2390
2393
2391
- if sys .platform == "win32" :
2392
- # Workaround for https://github.com/Theano/Theano/issues/4926.
2393
- # https://github.com/python/cpython/pull/11283/ removed the "hypot"
2394
- # redefinition for recent CPython versions (>=2.7.16 and >=3.7.3).
2395
- # The following nullifies that redefinition, if it is found.
2396
- python_version = sys .version_info [:3 ]
2397
- if (3 ,) <= python_version < (3 , 7 , 3 ):
2398
- config_h_filename = get_config_h_filename ()
2399
- try :
2400
- with open (config_h_filename ) as config_h :
2401
- if any (
2402
- line .startswith ("#define hypot _hypot" ) for line in config_h
2403
- ):
2404
- cxxflags .append ("-D_hypot=hypot" )
2405
- except OSError :
2406
- pass
2407
-
2408
2394
return cxxflags
2409
2395
2410
2396
@classmethod
@@ -2555,8 +2541,9 @@ def compile_str(
2555
2541
2556
2542
"""
2557
2543
# TODO: Do not do the dlimport in this function
2558
-
2559
2544
if not config .cxx :
2545
+ from pytensor .link .c .exceptions import MissingGXX
2546
+
2560
2547
raise MissingGXX ("g++ not available! We can't compile c code." )
2561
2548
2562
2549
if include_dirs is None :
@@ -2586,6 +2573,8 @@ def compile_str(
2586
2573
cppfile .write ("\n " )
2587
2574
2588
2575
if platform .python_implementation () == "PyPy" :
2576
+ from setuptools ._distutils .sysconfig import get_config_var
2577
+
2589
2578
suffix = "." + get_lib_extension ()
2590
2579
2591
2580
dist_suffix = get_config_var ("SO" )
@@ -2642,6 +2631,8 @@ def print_command_line_error():
2642
2631
status = p_out [2 ]
2643
2632
2644
2633
if status :
2634
+ from pytensor .link .c .exceptions import CompileError
2635
+
2645
2636
tf = tempfile .NamedTemporaryFile (
2646
2637
mode = "w" , prefix = "pytensor_compilation_error_" , delete = False
2647
2638
)
0 commit comments