Skip to content

Commit

Permalink
Python: Move bundled netCDF4 submodule
Browse files Browse the repository at this point in the history
Very importantly, this avoids the `examples` directory, with its 134MB
of `.nc` files, getting copied into the wheel
  • Loading branch information
ZedThree committed Oct 9, 2023
1 parent d96bd6f commit c056d3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/nc_complex/netCDF4"]
path = src/nc_complex/netCDF4
path = external/netCDF4
url = https://github.com/PlasmaFAIR/netcdf4-python.git
11 changes: 7 additions & 4 deletions src/nc_complex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,34 @@ set_target_properties(_c_nc_complex PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
)

# Path to the netCDF4 submodule
set(_external_netCDF4_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../external/netCDF4")

# We make a copy of the bundled _netCDF4.pyx in order to give it a
# different name and avoid clashes with the original when importing
# (even though this is in a different namespace, because it's a
# compiled module, it'll end up with the same name for the actual .so,
# and we have fun with linking/dynamic loading)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/netCDF4/src/netCDF4/_netCDF4.pyx"
configure_file("${_external_netCDF4_dir}/src/netCDF4/_netCDF4.pyx"
"${CMAKE_CURRENT_BINARY_DIR}/_pf_netCDF4.pyx"
COPYONLY
)
add_custom_command(
OUTPUT _pf_netCDF4.c
DEPENDS netCDF4/src/netCDF4/_netCDF4.pyx
DEPENDS "${_external_netCDF4_dir}/src/netCDF4/_netCDF4.pyx"
VERBATIM
COMMAND "${CYTHON}" "${CMAKE_CURRENT_BINARY_DIR}/_pf_netCDF4.pyx"
--output-file "${CMAKE_CURRENT_BINARY_DIR}/_pf_netCDF4.c"
--include-dir "${CMAKE_CURRENT_BINARY_DIR}"
--include-dir "${CMAKE_CURRENT_SOURCE_DIR}"
--include-dir "${CMAKE_CURRENT_SOURCE_DIR}/netCDF4/include"
--include-dir "${_external_netCDF4_dir}/include"
--3str
)

python_add_library(_pf_netCDF4 MODULE
"${CMAKE_CURRENT_BINARY_DIR}/_pf_netCDF4.c"
WITH_SOABI)
target_include_directories(_pf_netCDF4 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/netCDF4/include")
target_include_directories(_pf_netCDF4 PRIVATE "${_external_netCDF4_dir}/include")
target_link_libraries(_pf_netCDF4 PUBLIC netCDF::netcdf PRIVATE Python::NumPy nc_complex)
set_target_properties(_pf_netCDF4 PROPERTIES
INSTALL_RPATH "$ORIGIN"
Expand Down

0 comments on commit c056d3b

Please sign in to comment.