Skip to content

Commit

Permalink
Merge pull request #12 from PlasmaFAIR/custom_cython
Browse files Browse the repository at this point in the history
Add custom cython SDF reader
  • Loading branch information
ZedThree authored Oct 17, 2024
2 parents 6ea7f96 + bee786b commit a5dff98
Show file tree
Hide file tree
Showing 7 changed files with 807 additions and 93 deletions.
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ target_include_directories(sdfc PUBLIC

find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)

set(_sdf_module_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/sdf_xarray")
set(_sdf_input "${_sdf_module_dir}/sdf_interface.pyx")
set(_sdf_output "sdf_interface.c")
add_custom_command(
OUTPUT ${_sdf_output}
COMMENT
"Making ${CMAKE_CURRENT_BINARY_DIR}/${_sdf_output} from ${_sdf_input}"
COMMAND Python::Interpreter -m cython
"${_sdf_input}" --output-file ${_sdf_output}
"-I${_sdf_module_dir}"
-3
DEPENDS "${_sdf_input}"
VERBATIM)

python_add_library(sdf_interface MODULE ${_sdf_output} WITH_SOABI)
target_link_libraries(sdf_interface PRIVATE sdfc Python::NumPy)
target_compile_definitions(sdf_interface PRIVATE "NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION")

python_add_library(sdf MODULE SDF/utilities/sdf_python.c WITH_SOABI)
target_link_libraries(sdf PRIVATE sdfc Python::NumPy)

install(TARGETS sdf DESTINATION ${SKBUILD_PROJECT_NAME})
install(TARGETS sdf sdf_interface DESTINATION ${SKBUILD_PROJECT_NAME})
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = [
"scikit-build-core>=0.3",
"setuptools_scm",
"numpy>=2.0.0",
"cython>=3.0",
]
build-backend = "scikit_build_core.build"

Expand All @@ -20,6 +21,7 @@ dependencies = [
"numpy>=2.0.0",
"xarray>=2024.1.0",
"dask>=2024.7.1",
"cython>=3.0",
]

[project.optional-dependencies]
Expand Down
Loading

0 comments on commit a5dff98

Please sign in to comment.