mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Fixes after splitting the Cython module
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
# the wheel file if they are also listed in setup.cfg:options.package_data and not
|
||||
# listed in setup.cfg:options.exclude_package_data.
|
||||
|
||||
include cantera/_cantera.cpp
|
||||
recursive-include cantera *.cpp
|
||||
recursive-include cantera *.h
|
||||
recursive-include cantera *.pyx
|
||||
recursive-include cantera *.pxd
|
||||
include sundials_config.h.in
|
||||
include config.h.in
|
||||
graft include
|
||||
|
||||
# The C/C++ files in these folders are included automatically because they're in
|
||||
|
||||
@@ -45,6 +45,7 @@ install_requires =
|
||||
packaging
|
||||
python_requires @py_requires_ver_str@
|
||||
packages =
|
||||
cantera
|
||||
cantera.data
|
||||
cantera.examples
|
||||
cantera.test
|
||||
|
||||
@@ -8,13 +8,14 @@ from pathlib import Path
|
||||
import numpy
|
||||
import shutil
|
||||
|
||||
PY_SRC = Path("cantera")
|
||||
CT_SRC = Path("src")
|
||||
EXT_SRC = Path("ext")
|
||||
CT_INCLUDE = Path("include")
|
||||
BOOST_INCLUDE = None
|
||||
FORCE_CYTHON_COMPILE = False
|
||||
|
||||
CYTHON_BUILT_FILES = [Path("cantera") / f"_cantera.{ext}" for ext in ("cpp", "h")]
|
||||
CYTHON_BUILT_FILES = [pth.with_suffix(".cpp") for pth in PY_SRC.glob("*.pyx")]
|
||||
|
||||
|
||||
class CanteraOptionsMixin:
|
||||
@@ -22,6 +23,7 @@ class CanteraOptionsMixin:
|
||||
|
||||
Modeled after https://stackoverflow.com/a/53833930
|
||||
"""
|
||||
|
||||
user_options = [
|
||||
("force-cython-compile", None, "Force compilation of .pyx files via Cython"),
|
||||
("boost-include", None, "Location of the Boost header files."),
|
||||
@@ -46,13 +48,15 @@ class CanteraOptionsMixin:
|
||||
|
||||
|
||||
class InstallCommand(CanteraOptionsMixin, install):
|
||||
user_options = (getattr(install, "user_options", [])
|
||||
+ CanteraOptionsMixin.user_options)
|
||||
user_options = (
|
||||
getattr(install, "user_options", []) + CanteraOptionsMixin.user_options
|
||||
)
|
||||
|
||||
|
||||
class DevelopCommand(CanteraOptionsMixin, develop):
|
||||
user_options = (getattr(develop, "user_options", [])
|
||||
+ CanteraOptionsMixin.user_options)
|
||||
user_options = (
|
||||
getattr(develop, "user_options", []) + CanteraOptionsMixin.user_options
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
@@ -62,6 +66,7 @@ if (
|
||||
or os.environ.get("FORCE_CYTHON_COMPILE", False)
|
||||
):
|
||||
from Cython.Build import cythonize
|
||||
|
||||
CYTHON_EXT = ".pyx"
|
||||
for p in CYTHON_BUILT_FILES:
|
||||
if p.exists():
|
||||
@@ -69,12 +74,13 @@ if (
|
||||
else:
|
||||
CYTHON_EXT = ".cpp"
|
||||
|
||||
def cythonize(extensions):
|
||||
def cythonize(extensions, **kwargs):
|
||||
"""Define a no-op for when we're not using Cython."""
|
||||
return extensions
|
||||
|
||||
source_files = ["cantera/_cantera" + CYTHON_EXT]
|
||||
source_files += list(map(str, CT_SRC.glob("**/*.cpp")))
|
||||
|
||||
ct_sources = list(map(str, CT_SRC.glob("**/*.cpp")))
|
||||
py_sources = list(map(str, PY_SRC.glob(f"*{CYTHON_EXT}")))
|
||||
sundials_sources = list(map(str, EXT_SRC.glob("sundials/**/*.c")))
|
||||
yaml_cpp_sources = list(map(str, EXT_SRC.glob("yaml-cpp/**/*.cpp")))
|
||||
fmt_sources = list(map(str, EXT_SRC.glob("fmt/*.cc")))
|
||||
@@ -83,7 +89,8 @@ include_dirs = [
|
||||
str(CT_INCLUDE),
|
||||
str(CT_INCLUDE / "cantera" / "ext"),
|
||||
str(CT_SRC),
|
||||
numpy.get_include()
|
||||
"cantera",
|
||||
numpy.get_include(),
|
||||
]
|
||||
|
||||
if "BOOST_INCLUDE" in os.environ:
|
||||
@@ -94,8 +101,12 @@ elif BOOST_INCLUDE is not None:
|
||||
|
||||
def configure_build():
|
||||
boost_version = ""
|
||||
boost_locs = (os.environ.get("BOOST_INCLUDE", None), BOOST_INCLUDE, "/usr/include",
|
||||
"/usr/local/include")
|
||||
boost_locs = (
|
||||
os.environ.get("BOOST_INCLUDE", None),
|
||||
BOOST_INCLUDE,
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
)
|
||||
for boost_dir in boost_locs:
|
||||
if boost_dir is None:
|
||||
continue
|
||||
@@ -123,24 +134,22 @@ def configure_build():
|
||||
f"Could not convert Boost minor version to integer: '{boost_version}'"
|
||||
) from None
|
||||
if boost_minor_version < 61:
|
||||
raise ValueError(
|
||||
"Cantera requires Boost version 1.61 or newer."
|
||||
)
|
||||
raise ValueError("Cantera requires Boost version 1.61 or newer.")
|
||||
|
||||
if sys.platform != "win32":
|
||||
extra_compile_flags = ["-std=c++17", "-g0"]
|
||||
sundials_configh = {
|
||||
"SUNDIALS_USE_GENERIC_MATH": "#define SUNDIALS_USE_GENERIC_MATH 1",
|
||||
"SUNDIALS_BLAS_LAPACK": "/* #undef SUNDIALS_BLAS_LAPACK */"
|
||||
"SUNDIALS_BLAS_LAPACK": "/* #undef SUNDIALS_BLAS_LAPACK */",
|
||||
}
|
||||
sundials_cflags = ["-w"]
|
||||
sundials_macros = []
|
||||
else:
|
||||
extra_compile_flags = []
|
||||
extra_compile_flags = ["/EHsc", "/std:c++17"]
|
||||
sundials_macros = [("_CRT_SECURE_NO_WARNINGS", None)]
|
||||
sundials_configh = {
|
||||
"SUNDIALS_USE_GENERIC_MATH": "/* #undef SUNDIALS_USE_GENERIC_MATH */",
|
||||
"SUNDIALS_BLAS_LAPACK": "/* #undef SUNDIALS_BLAS_LAPACK */"
|
||||
"SUNDIALS_BLAS_LAPACK": "/* #undef SUNDIALS_BLAS_LAPACK */",
|
||||
}
|
||||
sundials_cflags = []
|
||||
|
||||
@@ -160,31 +169,37 @@ else:
|
||||
sundials_cflags = []
|
||||
sundials_macros = []
|
||||
|
||||
extensions = cythonize([
|
||||
Extension(
|
||||
"cantera._cantera",
|
||||
source_files,
|
||||
include_dirs=include_dirs,
|
||||
extra_compile_args=extra_compile_flags,
|
||||
language="c++",
|
||||
),
|
||||
])
|
||||
|
||||
|
||||
def lib_def(sources, cflags, include_dirs, macros):
|
||||
"""Convenience factory to create the dictionary for a Setuptools library build."""
|
||||
return dict(sources=sources, cflags=cflags, include_dirs=include_dirs,
|
||||
macros=macros)
|
||||
return dict(
|
||||
sources=sources, cflags=cflags, include_dirs=include_dirs, macros=macros
|
||||
)
|
||||
|
||||
|
||||
sundials_inc_dir = include_dirs + [str(EXT_SRC / "sundials" / "sundials")]
|
||||
libraries = [
|
||||
("sundials", lib_def(sundials_sources, sundials_cflags, sundials_inc_dir,
|
||||
sundials_macros)),
|
||||
(
|
||||
"sundials",
|
||||
lib_def(sundials_sources, sundials_cflags, sundials_inc_dir, sundials_macros),
|
||||
),
|
||||
("yaml-cpp", lib_def(yaml_cpp_sources, extra_compile_flags, include_dirs, [])),
|
||||
("fmtlib", lib_def(fmt_sources, extra_compile_flags, include_dirs, [])),
|
||||
]
|
||||
|
||||
extensions = cythonize(
|
||||
[
|
||||
Extension(
|
||||
name=f"cantera._cantera",
|
||||
sources=py_sources + ct_sources,
|
||||
include_dirs=include_dirs,
|
||||
extra_compile_args=extra_compile_flags,
|
||||
language="c++",
|
||||
)
|
||||
],
|
||||
compiler_directives={"binding": True, "language_level": 3},
|
||||
)
|
||||
|
||||
setup(
|
||||
ext_modules=extensions,
|
||||
libraries=libraries,
|
||||
|
||||
Reference in New Issue
Block a user