From 9331b9261afe887a1ce968e35a408895e8aacd2c Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Fri, 17 Nov 2023 18:08:41 +0100 Subject: [PATCH 1/3] Update setup.py to follow latest numpy and cython docs --- pyproject.toml | 2 +- setup.py | 75 +++++++++++++++++++------------------------------- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 269f339..3660e81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=64", "Cython", "oldest-supported-numpy", 'setuptools_scm[toml]>=8'] +requires = ["setuptools>=64", "Cython", "numpy>=1.25", 'setuptools_scm[toml]>=8'] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 7cbd324..4cde242 100644 --- a/setup.py +++ b/setup.py @@ -1,63 +1,44 @@ -from setuptools import setup +from setuptools import setup, Extension import os - -# make sure users without cython can install our extensions -try: - from Cython.Distutils.extension import Extension - from Cython.Distutils import build_ext as _build_ext - USE_CYTHON = True -except ImportError: - from setuptools import Extension - from setuptools.command.build_ext import build_ext as _build_ext - USE_CYTHON = False - -print('using cython', USE_CYTHON) - - -# make sure numpy is installed before we try to build -# the extenion -class build_ext(_build_ext): - def finalize_options(self): - super().finalize_options() - import numpy - self.include_dirs.append(numpy.get_include()) - +from Cython.Build import cythonize +import numpy as np + + +kwargs = dict( + include_dirs=[np.get_include()], + define_macros=[ + # fixes a warning when compiling + ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), + # defines the oldest numpy we want to be compatible with + ("NPY_TARGET_VERSION", "NPY_1_21_API_VERSION"), + ] +) # if we have cython, use the cython file if not the c file -ext = '.pyx' if USE_CYTHON else '.c' extensions = [ - Extension('eventio.header', sources=['src/eventio/header' + ext]), - Extension('eventio.var_int', sources=['src/eventio/var_int' + ext]), + Extension( + 'eventio.header', + sources=['src/eventio/header.pyx'], + **kwargs, + ), + Extension( + 'eventio.var_int', + sources=['src/eventio/var_int.pyx'], + **kwargs, + ), Extension( 'eventio.simtel.parsing', - sources=['src/eventio/simtel/parsing' + ext] + sources=['src/eventio/simtel/parsing.pyx'], + **kwargs, ), ] -cmdclass = {'build_ext': build_ext} - -# give a nice error message if people cloned the -# repository and do not have cython installed -if ext == '.c': - sources = [] - for ext in extensions: - sources.extend(ext.sources) - if not all(os.path.isfile(s) for s in sources): - raise ImportError('You need `Cython` to build this project locally') - setup( use_scm_version={"write_to": os.path.join("src", "eventio", "_version.py")}, - - ext_modules=extensions, - cmdclass=cmdclass, - - package_data={ - 'eventio': ['*.c'], - 'eventio.simtel': ['*.c'], - }, + ext_modules=cythonize(extensions), python_requires='>=3.8', install_requires=[ - 'numpy', + 'numpy >= 1.21', 'corsikaio ~= 0.3.3', 'zstandard > 0.11.1', # memory leak in zstandard 0.11.1 'setuptools_scm', From 134517d826ccf7c88f49e6915faa90a7c3e6966c Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Mon, 20 Nov 2023 11:56:37 +0100 Subject: [PATCH 2/3] Drop python 3.8, add 3.12 --- .github/workflows/ci.yml | 2 +- setup.cfg | 5 ++--- setup.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba0e19..76a740a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 with: diff --git a/setup.cfg b/setup.cfg index 2bb8b30..bd67cc0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,11 +24,10 @@ classifiers = Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: 3 :: Only Topic :: Scientific/Engineering :: Astronomy Topic :: Scientific/Engineering :: Physics diff --git a/setup.py b/setup.py index 4cde242..dc4b4c1 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ setup( use_scm_version={"write_to": os.path.join("src", "eventio", "_version.py")}, ext_modules=cythonize(extensions), - python_requires='>=3.8', + python_requires='>=3.9', install_requires=[ 'numpy >= 1.21', 'corsikaio ~= 0.3.3', From ef8d1dda15e0314823490cacba6912094faaf17a Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Mon, 20 Nov 2023 12:34:06 +0100 Subject: [PATCH 3/3] Remove obsolete comment --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index dc4b4c1..281c623 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ ] ) -# if we have cython, use the cython file if not the c file extensions = [ Extension( 'eventio.header',