2626from typing import TYPE_CHECKING , Protocol , cast
2727
2828import 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- )
3529
3630# we will abuse the lockfile mechanism when reading and writing the registry
3731from pytensor .compile .compilelock import lock_ctx
3832from pytensor .configdefaults import config , gcc_version_str
3933from pytensor .configparser import BoolParam , StrParam
4034from pytensor .graph .op import Op
41- from pytensor .link .c .exceptions import CompileError , MissingGXX
4235from pytensor .utils import (
4336 LOCAL_BITWIDTH ,
4437 flatten ,
@@ -266,6 +259,8 @@ def list_code(self, ofile=sys.stdout):
266259
267260def _get_ext_suffix ():
268261 """Get the suffix for compiled extensions"""
262+ from setuptools ._distutils .sysconfig import get_config_var
263+
269264 dist_suffix = get_config_var ("EXT_SUFFIX" )
270265 if dist_suffix is None :
271266 dist_suffix = get_config_var ("SO" )
@@ -1697,6 +1692,8 @@ def get_gcc_shared_library_arg():
16971692
16981693
16991694def std_include_dirs ():
1695+ from setuptools ._distutils .sysconfig import get_python_inc
1696+
17001697 numpy_inc_dirs = [np .get_include ()]
17011698 py_inc = get_python_inc ()
17021699 py_plat_spec_inc = get_python_inc (plat_specific = True )
@@ -1709,6 +1706,12 @@ def std_include_dirs():
17091706
17101707@is_StdLibDirsAndLibsType
17111708def 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+
17121715 # We cache the results as on Windows, this trigger file access and
17131716 # this method is called many times.
17141717 if std_lib_dirs_and_libs .data is not None :
@@ -2388,23 +2391,6 @@ def join_options(init_part):
23882391 # xcode's version.
23892392 cxxflags .append ("-ld64" )
23902393
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-
24082394 return cxxflags
24092395
24102396 @classmethod
@@ -2555,8 +2541,9 @@ def compile_str(
25552541
25562542 """
25572543 # TODO: Do not do the dlimport in this function
2558-
25592544 if not config .cxx :
2545+ from pytensor .link .c .exceptions import MissingGXX
2546+
25602547 raise MissingGXX ("g++ not available! We can't compile c code." )
25612548
25622549 if include_dirs is None :
@@ -2586,6 +2573,8 @@ def compile_str(
25862573 cppfile .write ("\n " )
25872574
25882575 if platform .python_implementation () == "PyPy" :
2576+ from setuptools ._distutils .sysconfig import get_config_var
2577+
25892578 suffix = "." + get_lib_extension ()
25902579
25912580 dist_suffix = get_config_var ("SO" )
@@ -2642,6 +2631,8 @@ def print_command_line_error():
26422631 status = p_out [2 ]
26432632
26442633 if status :
2634+ from pytensor .link .c .exceptions import CompileError
2635+
26452636 tf = tempfile .NamedTemporaryFile (
26462637 mode = "w" , prefix = "pytensor_compilation_error_" , delete = False
26472638 )
0 commit comments