diff --git a/pyproject.toml b/pyproject.toml index 3e441ab74f..5378a2201e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,9 +2,8 @@ requires = [ "setuptools >= 65", "Cython", - 'oldest-supported-numpy', + 'numpy>=2.0.0rc1', 'setuptools_scm[toml] >= 8', - "extension-helpers", ] build-backend = "setuptools.build_meta" @@ -33,3 +32,17 @@ filterwarnings = [ "error::gammapy.utils.deprecation.GammapyDeprecationWarning", "error::matplotlib.MatplotlibDeprecationWarning", ] + + +[tool.setuptools_scm] +version_file = "gammapy/version.py" +version_file_template = """\ +# Note that we need to fall back to the hard-coded version if either +# setuptools_scm can't be imported or setuptools_scm can't determine the +# version, so we catch the generic 'Exception'. +try: + from setuptools_scm import get_version + version = get_version(root='..', relative_to=__file__) +except Exception: + version = '{version}' +""" diff --git a/setup.py b/setup.py index 935cc1e5cf..af6ab33e7e 100755 --- a/setup.py +++ b/setup.py @@ -3,11 +3,7 @@ # NOTE: The configuration for the package, including the name, version, and # other information are set in the setup.cfg file. - -import os import sys -from extension_helpers import get_extensions -from setuptools import setup # First provide helpful messages if contributors try and run legacy commands # for tests or docs. @@ -62,21 +58,31 @@ print(DOCS_HELP) sys.exit(1) -VERSION_TEMPLATE = """ -# Note that we need to fall back to the hard-coded version if either -# setuptools_scm can't be imported or setuptools_scm can't determine the -# version, so we catch the generic 'Exception'. -try: - from setuptools_scm import get_version - version = get_version(root='..', relative_to=__file__) -except Exception: - version = '{version}' -""".lstrip() + +# imports here so that people get the nice error messages above without needing +# build dependencies +import numpy as np # noqa: E402 +from Cython.Build import cythonize # noqa: E402 +from setuptools import Extension, setup # noqa: E402 + +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"), + ], +) + +extensions = [ + Extension( + "gammapy.stats.fit_statistics_cython", + sources=["gammapy/stats/fit_statistics_cython.pyx"], + **kwargs, + ), +] setup( - use_scm_version={ - "write_to": os.path.join("gammapy", "version.py"), - "write_to_template": VERSION_TEMPLATE, - }, - ext_modules=get_extensions(), + ext_modules=cythonize(extensions), )