Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace numpy.distutils with CMake and scikit-build-core build backend #87

Merged
merged 8 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
# The executor is the environment in which the steps below will be executed - below will use a python 3.9 container
# Change the version below to your required version of python
docker:
- image: ubuntu:bionic
- image: cimg/base:current
environment:
CONDA_PREFIX: /root/tools/miniforge
PYSOLID_HOME: /root/tools/PySolid
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Scikit-build temp directory
/_skbuild/
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Based on:
# https://github.com/scikit-build/scikit-build-core/tree/main/docs/examples/getting_started/fortran

cmake_minimum_required(VERSION 3.17.2...3.29)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran)

find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)

# F2PY headers
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import numpy.f2py; print(numpy.f2py.get_include())"
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

add_library(fortranobject OBJECT "${F2PY_INCLUDE_DIR}/fortranobject.c")
target_link_libraries(fortranobject PUBLIC Python::NumPy)
target_include_directories(fortranobject PUBLIC "${F2PY_INCLUDE_DIR}")
set_property(TARGET fortranobject PROPERTY POSITION_INDEPENDENT_CODE ON)

add_custom_command(
OUTPUT solidmodule.c solid-f2pywrappers.f
DEPENDS src/pysolid/solid.for
VERBATIM
COMMAND "${Python_EXECUTABLE}" -m numpy.f2py
"${CMAKE_CURRENT_SOURCE_DIR}/src/pysolid/solid.for" -m solid --lower)

python_add_library(
solid MODULE "${CMAKE_CURRENT_BINARY_DIR}/solidmodule.c"
"${CMAKE_CURRENT_BINARY_DIR}/solid-f2pywrappers.f"
"${CMAKE_CURRENT_SOURCE_DIR}/src/pysolid/solid.for" WITH_SOABI)
target_link_libraries(solid PRIVATE fortranobject)

install(TARGETS solid DESTINATION pysolid)
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ python -m pip install -r PySolid/requirements.txt -r PySolid/tests/requirements.
python -m pip install PySolid

# option 2: use pip to install pysolid in develop mode (editable) into the current environment
# setting an environmental variable as below is required for editable installs via pyproject.toml
export SETUPTOOLS_ENABLE_FEATURES="legacy-editable"
python -m pip install -e PySolid

# option 3: manually compile the Fortran code and setup environment variable
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools<60.0", "setuptools_scm[toml]>=6.2", "numpy<1.23.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["cmake", "scikit-build-core", "setuptools", "setuptools_scm[toml]>=6.2", "numpy", "wheel"]
build-backend = "scikit_build_core.build"

[project]
name = "pysolid"
Expand Down Expand Up @@ -54,3 +54,6 @@ pysolid = ["*.for"]
[tool.setuptools_scm]
version_scheme = "post-release"
local_scheme = "no-local-version"

[tool.scikit-build]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# always prefer setuptools over distutils
import setuptools
from numpy.distutils.core import setup, Extension
from skbuild import setup

# read the contents of README file
def readme():
Expand Down Expand Up @@ -53,9 +53,4 @@ def readme():
package_data={
"pysolid": ["solid.for"],
},

## fortran extensions to build with numpy.f2py
ext_modules=[
Extension(name="pysolid.solid", sources=["src/pysolid/solid.for"])
],
)
2 changes: 1 addition & 1 deletion src/pysolid/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
Tag('Shallow water terdiurnal' , r'$MK_3$' , 8.177140247, 44.0251729, 365.555, 8 ),
Tag('Shallow water overtides of principal solar', r'$S_4$' , 6.0 , 60.0 , 491.555, 9 ),
Tag('Shallow water quarter diurnal' , r'$MN_4$' , 6.269173724, 57.4238337, 445.655, 10),
Tag('Shallow water overtides of principal solar', r'$S_6$' , 4.0 , 90.0 , np.NaN , 12),
Tag('Shallow water overtides of principal solar', r'$S_6$' , 4.0 , 90.0 , np.nan , 12),
Tag('Lunar terdiurnal' , r'$M_3$' , 8.280400802, 43.4761563, 355.555, 32),
Tag('Shallow water terdiurnal' , '2"MK'+r'$_3$', 8.38630265 , 42.9271398, 345.555, 34),
Tag('Shallow water eighth diurnal' , r'$M_8$' , 3.105150301, 115.9364166, 855.555, 36),
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# for packaging and installation
#fortran-compiler # Fortran compiler across platforms through conda-forge channel
meson
pip
setuptools_scm>=6.2
# for testing
Expand Down
Loading