Skip to content

Commit

Permalink
Compile against numpy 2.0 when building wheels, define target api ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
maxnoe committed Apr 16, 2024
1 parent c16ef3c commit f34fffa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
17 changes: 15 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}'
"""
44 changes: 25 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
)

0 comments on commit f34fffa

Please sign in to comment.