From 9710ef92dd844906623ff56b48072e0e03d9707c Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Tue, 14 Oct 2025 15:39:46 -0600 Subject: [PATCH 1/6] don't use cythonize in setup.py --- pyproject.toml | 4 ++-- setup.py | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 05298983..ff8ab3e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,8 +6,7 @@ readme = "README.md" authors = [ { name="Jeff Whitaker", email="whitaker.jeffrey@gmail.com"} ] -license = "MIT" -license-files = ["LICENSE"] +license = {text = "MIT"} classifiers = [ 'Development Status :: 5 - Production/Stable', 'Operating System :: MacOS :: MacOS X', @@ -41,6 +40,7 @@ dev = [ [build-system] requires = [ "setuptools>=77.0.1", + "setuptools_scm[toml]>=3.4", "cython>=0.29.20", "numpy>=2.0.0,<3", ] diff --git a/setup.py b/setup.py index eed7048f..2d095a23 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ import sys import numpy -from Cython.Build import cythonize from setuptools import Command, Extension, setup @@ -28,6 +27,7 @@ NAME = 'cftime' CFTIME_DIR = os.path.join(SRCDIR, NAME) CYTHON_FNAME = os.path.join(CFTIME_DIR, '_{}.pyx'.format(NAME)) +CYTHON_CNAME = os.path.join(CFTIME_DIR, '_{}.c'.format(NAME)) class CleanCython(Command): @@ -53,8 +53,7 @@ def run(self): print('clean: skipping file {!r}'.format(artifact)) -if ((FLAG_COVERAGE in sys.argv or os.environ.get('CYTHON_COVERAGE', None)) - and cythonize): +if FLAG_COVERAGE in sys.argv or os.environ.get('CYTHON_COVERAGE', None): COMPILER_DIRECTIVES = { **COMPILER_DIRECTIVES, **COVERAGE_COMPILER_DIRECTIVES } @@ -68,16 +67,21 @@ def run(self): if any([arg in CMDS_NOCYTHONIZE for arg in sys.argv]): ext_modules = [] else: - extension = Extension('{}._{}'.format(NAME, NAME), - sources=[os.path.relpath(CYTHON_FNAME, BASEDIR)], - define_macros=DEFINE_MACROS, - include_dirs=[numpy.get_include(),]) + ext_modules = [Extension('{}._{}'.format(NAME, NAME), + sources=[os.path.relpath(CYTHON_FNAME, BASEDIR)], + define_macros=DEFINE_MACROS, + include_dirs=[numpy.get_include(),])] + for e in ext_modules: + e.cython_directives = {'language_level': "3"} + e.compiler_directives = COMPILER_DIRECTIVES - ext_modules = cythonize( - extension, - compiler_directives=COMPILER_DIRECTIVES, - language_level=3, - ) +if 'sdist' not in sys.argv[1:] and 'clean' not in sys.argv[1:] and '--version' not in sys.argv[1:]: + # remove _cftime.c file if it exists, so cython will recompile _netCDF4.pyx. + # run for build *and* install (issue #263). Otherwise 'pip install' will + # not regenerate _netCDF4.c, even if the C lib supports the new features. + if len(sys.argv) >= 2: + if os.path.exists(CYTHON_CNAME): + os.remove(CYTHON_CNAME) setup( cmdclass={'clean_cython': CleanCython}, From ffa6f29c1a34f6fb43d29bbe8ca129aa3d06e4cc Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Tue, 14 Oct 2025 15:41:49 -0600 Subject: [PATCH 2/6] update --- pyproject.toml | 1 - setup.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ff8ab3e9..b60a2417 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,6 @@ dev = [ [build-system] requires = [ "setuptools>=77.0.1", - "setuptools_scm[toml]>=3.4", "cython>=0.29.20", "numpy>=2.0.0,<3", ] diff --git a/setup.py b/setup.py index 2d095a23..d08f335f 100644 --- a/setup.py +++ b/setup.py @@ -76,9 +76,9 @@ def run(self): e.compiler_directives = COMPILER_DIRECTIVES if 'sdist' not in sys.argv[1:] and 'clean' not in sys.argv[1:] and '--version' not in sys.argv[1:]: - # remove _cftime.c file if it exists, so cython will recompile _netCDF4.pyx. + # remove _cftime.c file if it exists, so cython will recompile _cftime.pyx. # run for build *and* install (issue #263). Otherwise 'pip install' will - # not regenerate _netCDF4.c, even if the C lib supports the new features. + # not regenerate _cftime.c, even if the C lib supports the new features. if len(sys.argv) >= 2: if os.path.exists(CYTHON_CNAME): os.remove(CYTHON_CNAME) From 6bdd0ff243b1bd9126a8c33451e8ff06b82a33a5 Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Tue, 14 Oct 2025 15:45:03 -0600 Subject: [PATCH 3/6] update --- setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.py b/setup.py index d08f335f..a1f9c606 100644 --- a/setup.py +++ b/setup.py @@ -74,11 +74,7 @@ def run(self): for e in ext_modules: e.cython_directives = {'language_level': "3"} e.compiler_directives = COMPILER_DIRECTIVES - -if 'sdist' not in sys.argv[1:] and 'clean' not in sys.argv[1:] and '--version' not in sys.argv[1:]: # remove _cftime.c file if it exists, so cython will recompile _cftime.pyx. - # run for build *and* install (issue #263). Otherwise 'pip install' will - # not regenerate _cftime.c, even if the C lib supports the new features. if len(sys.argv) >= 2: if os.path.exists(CYTHON_CNAME): os.remove(CYTHON_CNAME) From 45cfe01bf3b7ecd07e91e05d46b834621545a335 Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Tue, 14 Oct 2025 16:07:19 -0600 Subject: [PATCH 4/6] add setuptools[scm] requirement --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index b60a2417..ff8ab3e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ dev = [ [build-system] requires = [ "setuptools>=77.0.1", + "setuptools_scm[toml]>=3.4", "cython>=0.29.20", "numpy>=2.0.0,<3", ] From 121442473d698938129831e62e03f251b7d8a020 Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Wed, 15 Oct 2025 11:41:40 -0600 Subject: [PATCH 5/6] remove len(sys.argv) --- setup.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a1f9c606..4e33dfea 100644 --- a/setup.py +++ b/setup.py @@ -75,9 +75,8 @@ def run(self): e.cython_directives = {'language_level': "3"} e.compiler_directives = COMPILER_DIRECTIVES # remove _cftime.c file if it exists, so cython will recompile _cftime.pyx. - if len(sys.argv) >= 2: - if os.path.exists(CYTHON_CNAME): - os.remove(CYTHON_CNAME) + if os.path.exists(CYTHON_CNAME): + os.remove(CYTHON_CNAME) setup( cmdclass={'clean_cython': CleanCython}, From 14f4e4811ab66e5d2a9411d8222b8c6aca2a0692 Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Wed, 15 Oct 2025 11:42:25 -0600 Subject: [PATCH 6/6] update --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ff8ab3e9..b60a2417 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,6 @@ dev = [ [build-system] requires = [ "setuptools>=77.0.1", - "setuptools_scm[toml]>=3.4", "cython>=0.29.20", "numpy>=2.0.0,<3", ]