Skip to content
Snippets Groups Projects
Commit 1f806626 authored by Kakay, Dr. Attila (FWIN) - 9524's avatar Kakay, Dr. Attila (FWIN) - 9524 :smiling_imp:
Browse files

Added C extensions similar to setup.py as an extension to the toml file.

parent 4eb34c35
No related branches found
No related tags found
2 merge requests!88Release of 2.0.0,!87Replacing setup.py with pyproject.toml
import os
import platform
from pathlib import Path
from setuptools import Extension
from setuptools.command.build_py import build_py as _build_py
from numpy import get_include
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
LOCAL_DIR = os.path.join(MODULE_DIR, "local")
LIB_DIR = os.path.join(LOCAL_DIR, "lib")
LIB_DIR64 = os.path.join(LOCAL_DIR, "lib64")
print(MODULE_DIR)
fem_core_path = Path("../tetrax/sample/mesh/fem_core").resolve()
c_sourcefiles = [
str(fem_core_path / p)
for p in [
"dense2D_onthefly.c",
"bessel_K1.c",
"akmag.c",
"rotation_mat.c",
"matutils.c",
"sorting.c",
"utils.c",
"bnd2d.c",
"opmatspm.c",
"galerkin.c",
"fempreproc.c",
"hotriang.c",
"dense3D.c",
"integration_of_functions.c",
]
]
compiler_extra_args = ["-O3", "-Wno-cpp", "-Wno-unused-function", "-Wall"]
if platform.system() == "Windows":
compiler_extra_args = []
# compiler_extra_args.append("-fopenmp")
compiler_extra_args.append("-std=c99")
#compiler_extra_links = ["-Wl,-rpath,{},-rpath,{}".format(LIB_DIR, LIB_DIR64)]
# com_link.append('-fopenmp')
class build_py(_build_py):
def run(self):
self.run_command("build_ext")
return super().run()
def initialize_options(self):
super().initialize_options()
if self.distribution.ext_modules == None:
self.distribution.ext_modules = []
self.distribution.ext_modules.append(
Extension(
"tetrax.sample.mesh.fem_core.cythoncore",
sources=[*c_sourcefiles, "tetrax/sample/mesh/fem_core/cythoncore.pyx"],
libraries=[],
library_dirs=[],
include_dirs=[str(fem_core_path), "main", get_include()],
extra_compile_args=compiler_extra_args,
# extra_link_args=compiler_extra_links,
)
#
# Extension(
# "termial_random.random",
# sources=["termial_random/random.c"],
# extra_compile_args=["-std=c17", "-lm"],
# )
)
\ No newline at end of file
[build-system] [build-system]
requires = ["setuptools", "cython"] requires = ["setuptools", "cython", "numpy"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] [project]
...@@ -32,11 +32,18 @@ dependencies = [ ...@@ -32,11 +32,18 @@ dependencies = [
"pooch", "pooch",
] ]
[tool.setuptools]
py-modules = ["_custom_build"]
[tool.setuptools.cmdclass]
build_py = "_custom_build.build_py"
[project.optional-dependencies] [project.optional-dependencies]
#dev = ["pytest", "pre-commit", "nbsphinx", "pydata-sphinx-theme", "jupyterlab"] #dev = ["pytest", "pre-commit", "nbsphinx", "pydata-sphinx-theme", "jupyterlab"]
#torch = ["torch", "torchdiffeq"] #torch = ["torch", "torchdiffeq"]
#jax = ["jax[cuda]>=0.4.31", "diffrax", "optax"] #jax = ["jax[cuda]>=0.4.31", "diffrax", "optax"]
[tool.setuptools.packages.find] [tool.setuptools.packages.find]
#include = ["neuralmag*"] #include = ["neuralmag*"]
...@@ -47,26 +54,3 @@ dependencies = [ ...@@ -47,26 +54,3 @@ dependencies = [
#profile = "black" #profile = "black"
#skip_gitignore = true # ignores files listed in .gitignore #skip_gitignore = true # ignores files listed in .gitignore
#skip_glob = ["/neuralmag/field_terms/code/*"] #skip_glob = ["/neuralmag/field_terms/code/*"]
[tool.setuptools]
ext-modules = [
{name = "tetrax.sample.mesh.fem_core.cythoncore",
sources = [
"tetrax/sample/mesh/fem_core/cythoncore.pyx",
"tetrax/sample/mesh/fem_core/dense2D_onthefly.c",
"tetrax/sample/mesh/fem_core/bessel_K1.c",
"tetrax/sample/mesh/fem_core/akmag.c",
"tetrax/sample/mesh/fem_core/rotation_mat.c",
"tetrax/sample/mesh/fem_core/matutils.c",
"tetrax/sample/mesh/fem_core/sorting.c",
"tetrax/sample/mesh/fem_core/utils.c",
"tetrax/sample/mesh/fem_core/bnd2d.c",
"tetrax/sample/mesh/fem_core/opmatspm.c",
"tetrax/sample/mesh/fem_core/galerkin.c",
"tetrax/sample/mesh/fem_core/fempreproc.c",
"tetrax/sample/mesh/fem_core/hotriang.c",
"tetrax/sample/mesh/fem_core/dense3D.c",
"tetrax/sample/mesh/fem_core/integration_of_functions.c"
]
}
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment