Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,28 @@ jobs:

- name: Build just oldest and newest on PRs, all on tags
shell: bash
# - Always omit musl 3.8 b/c NumPy does not provide wheels for it
# - Always omit musllinux_aarch64 because it's slow and niche
# - On PPs, omit musllinux for speed
# - On PRs, run just oldest and newest Python versions (and omit 3.8 aarch64)
# - On PRs, run just oldest and newest Python versions (3.13 is the oldest abi3 target)
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
CIBW_SKIP="cp38-* cp39-* cp310-* cp311-* cp38-*_aarch64 *musllinux*"
CIBW_SKIP="cp3{11,12}-* *musllinux*"
else
CIBW_SKIP="cp38-* *musllinux_aarch64"
CIBW_SKIP="*musllinux_aarch64"
fi
echo "CIBW_SKIP=$CIBW_SKIP" >> $GITHUB_ENV
echo "Setting CIBW_SKIP=$CIBW_SKIP"

- name: "Building ${{ matrix.os }} (${{ matrix.arch }}) wheels"
uses: pypa/cibuildwheel@v3.1.4
uses: pypa/cibuildwheel@v3.2.0
env:
CIBW_SKIP: ${{ env.CIBW_SKIP }}
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
# Emulated testing is slow, so trust that the Python 3.12 test is good enough on aarch64
# Emulated testing is slow, so trust that the Python 3.14 test is good enough on aarch64
# (takes about 5 minutes per wheel to build, and 5 minutes to test)
CIBW_TEST_SKIP: "cp39-*_aarch64 cp310-*_aarch64 cp311-*_aarch64"
CIBW_TEST_SKIP: "cp3{10,11,12,13}-*_aarch64"
CIBW_TEST_GROUPS: dev
CIBW_TEST_COMMAND: >
python -c "import cftime; print(f'cftime v{cftime.__version__}')" &&
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
os: [windows-latest, ubuntu-latest, macos-latest]
platform: [x64, x32]
experimental: [false]
Expand Down
26 changes: 21 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ classifiers = [
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'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.13',
'Programming Language :: Python :: 3.14',
'Topic :: Scientific/Engineering',
]
dependencies = [
"numpy>1.13.3",
]
requires-python = ">=3.8"
requires-python = ">=3.10"

[dependency-groups]
dev = [
Expand All @@ -44,8 +43,7 @@ dev = [
requires = [
"setuptools>=77.0.1",
"cython>=0.29.20",
"oldest-supported-numpy ; python_version < '3.9'",
"numpy>=2.0.0,<3 ; python_version >= '3.9'",
"numpy>=2.0.0,<3",
]
build-backend = "setuptools.build_meta"

Expand Down Expand Up @@ -103,3 +101,21 @@ ignore = [
"test",
"test/*",
]

[tool.cibuildwheel]
build-verbosity = 1
skip = [
"*musllinux_aarch64*",
]

# Emulated testing is slow, so trust that the Python 3.14 test is good enough on aarch64
# (takes about 5 minutes per wheel to build, and 5 minutes to test)
test-skip = [
"cp3{10,11,12,13}-*_aarch64",
]
test-groups = "dev"
test-command = [
'''python -c "import cftime; print(f'cftime v{cftime.__version__}')"''',
"python -m pytest -vv {package}/test"
]
environment = {CFTIME_LIMITED_API="1"}
22 changes: 21 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import sysconfig
import numpy

from Cython.Build import cythonize
Expand Down Expand Up @@ -29,6 +30,21 @@
CFTIME_DIR = os.path.join(SRCDIR, NAME)
CYTHON_FNAME = os.path.join(CFTIME_DIR, '_{}.pyx'.format(NAME))

USE_PY_LIMITED_API = (
# require opt-in (builds are specialized by default)
os.getenv('CFTIME_LIMITED_API', '0') == '1'
# Cython + numpy + limited API de facto requires Python >=3.13
and sys.version_info >= (3, 13)
# as of Python 3.14t, free-threaded builds don't support the limited API
and not sysconfig.get_config_var("Py_GIL_DISABLED")
)
ABI3_TARGET_VERSION = "".join(str(_) for _ in sys.version_info[:2])
ABI3_TARGET_HEX = hex(sys.hexversion & 0xFFFF00F0)

if USE_PY_LIMITED_API:
SETUP_OPTIONS = {"bdist_wheel": {"py_limited_api": f"cp{ABI3_TARGET_VERSION}"}}
else:
SETUP_OPTIONS = {}

class CleanCython(Command):
description = 'Purge artifacts built by Cython'
Expand Down Expand Up @@ -60,6 +76,8 @@ def run(self):
}
DEFINE_MACROS += [('CYTHON_TRACE', '1'),
('CYTHON_TRACE_NOGIL', '1')]
if USE_PY_LIMITED_API:
DEFINE_MACROS.append(("Py_LIMITED_API", ABI3_TARGET_HEX))
if FLAG_COVERAGE in sys.argv:
sys.argv.remove(FLAG_COVERAGE)
print('enable: "linetrace" Cython compiler directive')
Expand All @@ -71,7 +89,8 @@ def run(self):
extension = Extension('{}._{}'.format(NAME, NAME),
sources=[os.path.relpath(CYTHON_FNAME, BASEDIR)],
define_macros=DEFINE_MACROS,
include_dirs=[numpy.get_include(),])
include_dirs=[numpy.get_include()],
py_limited_api=USE_PY_LIMITED_API)

ext_modules = cythonize(
extension,
Expand All @@ -82,4 +101,5 @@ def run(self):
setup(
cmdclass={'clean_cython': CleanCython},
ext_modules=ext_modules,
options=SETUP_OPTIONS,
)
Loading