11"""Cython-based Python Module"""
22import re
33from pathlib import Path
4- from pkg_resources import parse_version
5- import json
64from buildutils import *
75
86Import ('env' , 'build' , 'install' )
@@ -15,70 +13,8 @@ build(dataFiles)
1513# Install Python samples
1614install (localenv .RecursiveInstall , "$inst_sampledir/python" , "#samples/python" )
1715
18- # Get information needed to build the Python module
19- script = """\
20- from sysconfig import *
21- import numpy
22- import json
23- import site
24- vars = get_config_vars()
25- vars["plat"] = get_platform()
26- vars["numpy_include"] = numpy.get_include()
27- vars["site_packages"] = [d for d in site.getsitepackages() if d.endswith("-packages")]
28- vars["user_site_packages"] = site.getusersitepackages()
29- print(json.dumps(vars))
30- """
31- info = json .loads (get_command_output (localenv ["python_cmd" ], "-c" , script ))
32- module_ext = info ["EXT_SUFFIX" ]
33- inc = info ["INCLUDEPY" ]
34- pylib = info .get ("LDLIBRARY" )
35- prefix = info ["prefix" ]
36- py_version_short = parse_version (info ["py_version_short" ])
37- py_version_full = parse_version (info ["py_version" ])
38- py_version_nodot = info ["py_version_nodot" ]
39- numpy_include = info ["numpy_include" ]
40- site_packages = info ["site_packages" ]
41- user_site_packages = info ["user_site_packages" ]
42- localenv .Prepend (CPPPATH = [Dir ('#include' ), inc , numpy_include ])
43- localenv .Prepend (LIBS = localenv ['cantera_libs' ])
44-
45- # Fix the module extension for Windows from the sysconfig library.
46- # See https://github.com/python/cpython/pull/22088 and
47- # https://bugs.python.org/issue39825
48- if (
49- py_version_full < parse_version ("3.8.7" )
50- and localenv ["OS" ] == "Windows"
51- and module_ext == ".pyd"
52- ):
53- module_ext = f".cp{ py_version_nodot } -{ info ['plat' ].replace ('-' , '_' )} .pyd"
54-
55- # Don't print deprecation warnings for internal Python changes.
56- # Only applies to Python 3.8. The field that is deprecated in Python 3.8
57- # and causes the warnings to appear will be removed in Python 3.9 so no
58- # further warnings should be issued.
59- if localenv ["HAS_CLANG" ] and py_version_short == parse_version ("3.8" ):
60- localenv .Append (CXXFLAGS = '-Wno-deprecated-declarations' )
61-
62- if "icc" in localenv ["CC" ]:
63- localenv .Append (CPPDEFINES = {"CYTHON_FALLTHROUGH" : " __attribute__((fallthrough))" })
64-
65- if localenv ['OS' ] == 'Darwin' :
66- localenv .Append (LINKFLAGS = '-undefined dynamic_lookup' )
67- elif localenv ['OS' ] == 'Windows' :
68- localenv .Append (LIBPATH = prefix + '/libs' )
69- if localenv ['toolchain' ] == 'mingw' :
70- localenv .Append (LIBS = f"python{ py_version_nodot } " )
71- if localenv ['OS_BITS' ] == 64 :
72- localenv .Append (CPPDEFINES = 'MS_WIN64' )
73- # Fix for https://bugs.python.org/issue11566. Fixed in 3.7.3 and higher.
74- # See https://github.com/python/cpython/pull/11283
75- if py_version_full < parse_version ("3.7.3" ):
76- localenv .Append (CPPDEFINES = {"_hypot" : "hypot" })
77-
78- if "numpy_1_7_API" in localenv :
79- localenv .Append (CPPDEFINES = "NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION" )
80-
81- localenv ["module_ext" ] = module_ext
16+ setup_python_env (localenv )
17+
8218setup_cfg = localenv .SubstFile ("setup.cfg" , "setup.cfg.in" )
8319readme = localenv .Command ("README.rst" , "#README.rst" , Copy ("$TARGET" , "$SOURCE" ))
8420license = localenv .Command ("LICENSE.txt" , "#build/ext/LICENSE.txt" ,
@@ -104,15 +40,15 @@ for pyxfile in multi_glob(localenv, "cantera", "pyx"):
10440 f"#build/temp-py/{ pyxfile .name .split ('.' )[0 ]} " , cythonized )
10541 cython_obj .append (obj )
10642
43+ module_ext = localenv ["py_module_ext" ]
10744ext = localenv .LoadableModule (f"cantera/_cantera{ module_ext } " ,
10845 cython_obj , LIBPREFIX = "" , SHLIBSUFFIX = module_ext ,
10946 SHLIBPREFIX = "" , LIBSUFFIXES = [module_ext ])
11047
11148build_cmd = ("$python_cmd_esc -m pip wheel -v --no-build-isolation --no-deps "
11249 "--wheel-dir=build/python/dist build/python" )
113- plat = info ['plat' ].replace ('-' , '_' ).replace ('.' , '_' )
114- wheel_name = (f"Cantera-{ env ['cantera_version' ]} -cp{ py_version_nodot } "
115- f"-cp{ py_version_nodot } -{ plat } .whl" )
50+ wheel_name = ("Cantera-${cantera_version}-cp${py_version_nodot}"
51+ "-cp${py_version_nodot}-${plat}.whl" )
11652mod = build (localenv .Command (f"#build/python/dist/{ wheel_name } " , "setup.cfg" ,
11753 build_cmd ))
11854env ['python_module' ] = mod
15389 ignore_errors = True )
15490
15591 if user_install :
156- test_prefix = Path (user_site_packages ).parents [2 ]
92+ test_prefix = Path (localenv [ " user_site_packages" ] ).parents [2 ]
15793 elif python_prefix is None :
158- test_prefix = Path (site_packages [0 ]).parents [2 ]
94+ test_prefix = Path (localenv [ " site_packages" ] [0 ]).parents [2 ]
15995 else :
16096 test_prefix = Path (python_prefix )
16197
0 commit comments