diff --git a/.circleci/config.yml b/.circleci/config.yml index 4ca5a14..e8ae932 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.gitignore b/.gitignore index 4d545e6..a97b3e2 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Scikit-build temp directory +/_skbuild/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..380a41f --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 1545ea6..3f12142 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 19637c7..0c28680 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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" diff --git a/setup.py b/setup.py index fe0a858..950ba53 100644 --- a/setup.py +++ b/setup.py @@ -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(): @@ -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"]) - ], ) diff --git a/src/pysolid/point.py b/src/pysolid/point.py index 9486d61..77b4df8 100644 --- a/src/pysolid/point.py +++ b/src/pysolid/point.py @@ -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), diff --git a/tests/requirements.txt b/tests/requirements.txt index 9277b34..7561558 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -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