Skip to content

Commit

Permalink
Adopt cython3 (require >=3) (#460)
Browse files Browse the repository at this point in the history
* Adopt cython3 (now required)

* Suppress the obsolete warning about numpy v1.7 api, only in Cython<3.

* Assert python 3 syntax for Cython source, just to be clear.

* remove unnecessary cibuildwheel option.

* Review changes : tweak comment.
  • Loading branch information
pp-mo authored Sep 20, 2024
1 parent 9efd012 commit 539dbcc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = [
"setuptools_scm[toml]>=7.0",
"wheel",
"oldest-supported-numpy",
"Cython"
"Cython>=3.0"
]
# Defined by PEP 517
build-backend = "setuptools.build_meta"
Expand Down
2 changes: 1 addition & 1 deletion requirements/cf-units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
# setup dependencies
- setuptools >=45
- setuptools_scm >=7.0
- cython
- cython >=3.0
- numpy

# core dependencies
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
cythonize = False

COMPILER_DIRECTIVES = {}
DEFINE_MACROS = None
# This Cython macro disables a build warning, obsolete with Cython>=3
# see : https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html#numpy-c-api
DEFINE_MACROS = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
FLAG_COVERAGE = "--cython-coverage" # custom flag enabling Cython line tracing
BASEDIR = Path(__file__).resolve().parent
PACKAGE = "cf_units"
Expand Down Expand Up @@ -119,7 +121,7 @@ def _set_builtin(name, value):

if FLAG_COVERAGE in sys.argv or environ.get("CYTHON_COVERAGE", None):
COMPILER_DIRECTIVES = {"linetrace": True}
DEFINE_MACROS = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
DEFINE_MACROS += [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
if FLAG_COVERAGE in sys.argv:
sys.argv.remove(FLAG_COVERAGE)
print('enable: "linetrace" Cython compiler directive')
Expand All @@ -142,6 +144,8 @@ def _set_builtin(name, value):
[udunits_ext] = cythonize(
udunits_ext,
compiler_directives=COMPILER_DIRECTIVES,
# Assert python 3 source syntax: Currently required to suppress a warning,
# even though this is now the default (as-of Cython v3).
language_level="3str",
)

Expand Down

0 comments on commit 539dbcc

Please sign in to comment.