From c701e28b9c479abacdd169bba1a1e689b0f28aca Mon Sep 17 00:00:00 2001 From: Felix Oesterle <6945681+fso42@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:07:30 +0100 Subject: [PATCH] feat(pyproject, setup): update dependencies and build configuration for NumPy and Cython compatibility; fixes #1228 refactor(pyproject): update `clean` task to use `pathlib` - Configured `setup.py` to ensure compatibility with NumPy <2.0 and Cython 3.x by adding appropriate macros (`NPY_NO_DEPRECATED_API`, `NPY_TARGET_VERSION`) in extensions. - Improved build directives for better handling of NumPy compatibility in Cython code. - Minor fixes in documentation for consistency (e.g., updated paths and corrected filenames). fix(pyproject): update python requirements to exclude 3.14 --- docs/developinstall.rst | 2 +- docs/developinstallwin.rst | 4 ++-- pyproject.toml | 20 +++++++------------- setup.py | 15 +++++++++++++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/docs/developinstall.rst b/docs/developinstall.rst index 8d76bcdfc..3a3f88e3c 100644 --- a/docs/developinstall.rst +++ b/docs/developinstall.rst @@ -10,7 +10,7 @@ guide is described for **Linux**. For *Windows*, see :ref:`developinstallwin:Adv Requirements ^^^^^^^^^^^^ -Install `git `_, python and `pixi `_. +Install `git `_ and `pixi `_. Some operating systems might require the python headers (e.g python-dev on ubuntu) or other supporting libraries/packages (e.g. Visual Studio on Windows needs the c++ compiler components). diff --git a/docs/developinstallwin.rst b/docs/developinstallwin.rst index a05baab7b..607aabd4f 100644 --- a/docs/developinstallwin.rst +++ b/docs/developinstallwin.rst @@ -10,7 +10,7 @@ guide is described for **Windows**. For *Linux*, see :ref:`developinstall:Advanc Requirements ^^^^^^^^^^^^ -Install `git `_, python and `pixi `_. +Install `git `_ and `pixi `_. Install `Microsoft C++ compiler `_. Follow the installation steps for the version corresponding to the installed python version. @@ -43,7 +43,7 @@ Compile the cython com1DFA part:: You will have to do this compilation every time something changes in the cython code. We also suggest to do this everytime updates from the repositories are pulled. - **Before** compilation in Windows, make sure to delete ``AvaFrame/build`` directory, in addition to any .pyd, .c, and + **Before** compilation in Windows, make sure to delete ``AvaFrame/build`` directory, in addition to any .pyc, .c, and .pycache files in ``AvaFrame/avaframe/com1DFA`` This installs avaframe in editable mode, so every time you import avaframe the diff --git a/pyproject.toml b/pyproject.toml index 401a71199..5b66aacc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] # Cython dependency is optional, see setup.py for details. # For the package (run-time) dependencies, see setup.cfg. -requires = ["setuptools", "numpy", "Cython", "setuptools-scm"] +requires = ["setuptools", "numpy<2.0", "Cython>=3.0.10", "setuptools-scm"] build-backend = "setuptools.build_meta" [project] @@ -26,13 +26,13 @@ classifiers = [ requires-python = ">=3.9,<3.14" dependencies = [ "numpy<2.0", # numpy 2.0 introduces breaking changes in relation to qgis versions - "salib<1.5.1", # this is the last aversion that works with numpy <2. - "pyshp<3.0", # pin until 3.0.3 is out, there's a known bug for certain polygon types + "salib", # this is the last aversion that works with numpy <2. + "pyshp>=3.0.3", # pin until 3.0.3 is out, there's a known bug for certain polygon types "matplotlib", "scipy", "cmcrameri", "seaborn", - "cython<3.0", # cython 3.x compiles code that needs numpy > 2.0 + "cython>=3.0.10", # Cython 3.x is required for Python 3.12/3.13, configured for numpy < 2.0 in setup.py "pandas", "shapely", "configUpdater", @@ -64,7 +64,7 @@ version_file = "avaframe/RELEASE-VERSION.txt" #build = ["cp312-*"] skip = ["*musllinux*","*-win32"] build-verbosity = 1 -before-build = "pip install cython numpy" +before-build = "pip install 'cython>=3.0.10' 'numpy<2.0'" [tool.cibuildwheel.linux] @@ -86,7 +86,7 @@ channels = ["https://prefix.dev/conda-forge"] platforms = ["linux-64", "win-64", "osx-64"] [tool.pixi.dependencies] -python = "<3.14" +python = ">=3.9,<3.14" setuptools = "*" setuptools-scm = "*" cibuildwheel = "*" @@ -114,17 +114,13 @@ sphinxcontrib-bibtex = "*" [tool.pixi.feature.prod.pypi-dependencies] avaframe = "*" -#Feature py313 -[tool.pixi.feature.py313.dependencies] -python = "==3.13.7" - #Feature rcs #[tool.pixi.feature.rcs.pypi-dependencies] #avaframe = "==1.13rc4" [tool.pixi.tasks] build = "python setup.py build_ext --inplace" -clean = "find avaframe -type f \\( -name '*.so' -o -name '*.c' \\) -delete" +clean = "python -c \"import pathlib; [f.unlink() for f in pathlib.Path('avaframe').rglob('*.so')]; [f.unlink() for f in pathlib.Path('avaframe').rglob('*.c')]\"" rebuild = { depends-on = ["clean", "build"] } #Feature qgis @@ -139,6 +135,4 @@ dev = ["dev"] doc = ["doc", "dev"] prod = ["prod"] #rcs = ["rcs"] -py313 = ["py313", "dev"] qgis = ["qgis", "dev"] - diff --git a/setup.py b/setup.py index 5f4fdf4cc..195bf1d42 100644 --- a/setup.py +++ b/setup.py @@ -13,11 +13,20 @@ 'avaframe/com1DFA/damCom1DFA.pyx', ] +# Define macros to ensure NumPy 1.x API compatibility +# This allows Cython 3.x to generate code that works with numpy < 2.0 +define_macros = [ + ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), + # Target NumPy 1.x C API even when building with Cython 3.x + ("NPY_TARGET_VERSION", "NPY_1_22_API_VERSION"), +] + extensions = [ Extension( name=file.replace('/', '.').replace('.pyx', ''), sources=[file], - include_dirs=[numpy.get_include()] + include_dirs=[numpy.get_include()], + define_macros=define_macros, # Add the macros here ) for file in cython_files ] @@ -27,6 +36,8 @@ compiler_directives={ 'language_level': '3', 'linetrace': True, + # Ensure Cython generates code compatible with older NumPy + 'binding': True, } ) @@ -43,4 +54,4 @@ # 'pandas' # ], # python_requires='>=3.8', -) \ No newline at end of file +)