Skip to content

Commit

Permalink
Implement support for the free-threaded build of CPython 3.13 (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Bull <git@sambull.org>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
4 people authored Feb 20, 2025
1 parent f560940 commit ccab7f4
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 19 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
strategy:
matrix:
pyver:
- 3.13t
- 3.13
- 3.12
- 3.11
Expand Down Expand Up @@ -238,9 +239,11 @@ jobs:
pattern: ${{ needs.pre-setup.outputs.dists-artifact-name }}*
merge-multiple: true

# TODO: Revert back to using actions/setup-python once the official
# action supports free-threaded Python
- name: Setup Python ${{ matrix.pyver }}
id: python-install
uses: actions/setup-python@v5
uses: quansight-labs/setup-python@v5
with:
python-version: ${{ matrix.pyver }}
allow-prereleases: true
Expand All @@ -257,7 +260,7 @@ jobs:
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
with:
path: requirements/test.txt
path: requirements/codspeed.txt
- name: Determine pre-compiled compatible wheel
env:
# NOTE: When `pip` is forced to colorize output piped into `jq`,
Expand Down Expand Up @@ -419,7 +422,7 @@ jobs:
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
with:
path: requirements/test.txt
path: requirements/codspeed.txt
- name: Determine pre-compiled compatible wheel
env:
# NOTE: When `pip` is forced to colorize output piped into `jq`,
Expand Down
1 change: 1 addition & 0 deletions CHANGES/84.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented support for the free-threaded build of CPython 3.13 -- by :user:`lysnikolaou`.
1 change: 1 addition & 0 deletions CHANGES/84.packaging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Started building wheels for the free-threaded build of CPython 3.13 -- by :user:`lysnikolaou`.
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Bluesky
Bugfixes
CPython
Changelog
Codecov
Cython
Expand Down
11 changes: 7 additions & 4 deletions packaging/pep517_backend/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

import os
import sysconfig
import typing as t
from contextlib import contextmanager, nullcontext, suppress
from functools import partial
Expand Down Expand Up @@ -371,10 +372,12 @@ def get_requires_for_build_wheel(
stacklevel=999,
)

c_ext_build_deps = [] if is_pure_python_build else [
'Cython ~= 3.0.0; python_version >= "3.12"',
'Cython; python_version < "3.12"',
]
if is_pure_python_build:
c_ext_build_deps = []
elif sysconfig.get_config_var('Py_GIL_DISABLED'):
c_ext_build_deps = ['Cython ~= 3.1.0a1']
else:
c_ext_build_deps = ['Cython ~= 3.0.12']

return _setuptools_get_requires_for_build_wheel(
config_settings=config_settings,
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ linetrace = "True" # Implies `profile=True`

[tool.cibuildwheel]
build-frontend = "build"
enable = ["cpython-freethreading"]
before-test = [
# NOTE: Attempt to have pip pre-compile PyYAML wheel with our build
# NOTE: constraints unset. The hope is that pip will cache that wheel
Expand Down Expand Up @@ -94,3 +95,12 @@ before-test = [] # Windows cmd has different syntax and pip chooses wheels

[tool.cibuildwheel.linux]
before-all = "yum install -y libffi-devel || apk add --upgrade libffi-dev || apt-get install libffi-dev"

# TODO: Remove this when there's a Cython 3.1 final release
# Remove PIP_CONSTRAINT from the environment
[[tool.cibuildwheel.overrides]]
select = "cp313t-*"

test-requires = "-r requirements/test-freethreading.txt"
inherit.environment = "append"
environment = {PIP_CONSTRAINT = "requirements/cython-freethreading.txt"}
2 changes: 2 additions & 0 deletions requirements/codspeed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r test.txt
pytest-codspeed==3.2.0
1 change: 1 addition & 0 deletions requirements/cython-freethreading.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cython==3.1.0a1
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r test.txt
-r codspeed.txt
-r towncrier.txt
2 changes: 2 additions & 0 deletions requirements/test-freethreading.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r cython-freethreading.txt
-r test-pure.txt
4 changes: 4 additions & 0 deletions requirements/test-pure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
covdefaults
pytest==8.3.4
pytest-cov>=2.3.1
pytest-xdist
6 changes: 1 addition & 5 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
-r cython.txt
covdefaults
pytest==8.3.4
pytest-codspeed==3.2.0
pytest-cov>=2.3.1
pytest-xdist
-r test-pure.txt
2 changes: 1 addition & 1 deletion src/propcache/_helpers_c.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cython: language_level=3
# cython: language_level=3, freethreading_compatible=True
from types import GenericAlias


Expand Down
15 changes: 10 additions & 5 deletions tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""codspeed benchmarks for propcache."""

from pytest_codspeed import BenchmarkFixture
import pytest

try:
from pytest_codspeed import BenchmarkFixture
except ImportError:
pytestmark = pytest.mark.skip("pytest_codspeed needs to be installed")

from propcache import cached_property, under_cached_property


def test_under_cached_property_cache_hit(benchmark: BenchmarkFixture) -> None:
def test_under_cached_property_cache_hit(benchmark: "BenchmarkFixture") -> None:
"""Benchmark for under_cached_property cache hit."""

class Test:
Expand All @@ -25,7 +30,7 @@ def _run() -> None:
t.prop


def test_cached_property_cache_hit(benchmark: BenchmarkFixture) -> None:
def test_cached_property_cache_hit(benchmark: "BenchmarkFixture") -> None:
"""Benchmark for cached_property cache hit."""

class Test:
Expand All @@ -45,7 +50,7 @@ def _run() -> None:
t.prop


def test_under_cached_property_cache_miss(benchmark: BenchmarkFixture) -> None:
def test_under_cached_property_cache_miss(benchmark: "BenchmarkFixture") -> None:
"""Benchmark for under_cached_property cache miss."""

class Test:
Expand All @@ -67,7 +72,7 @@ def _run() -> None:
t.prop


def test_cached_property_cache_miss(benchmark: BenchmarkFixture) -> None:
def test_cached_property_cache_miss(benchmark: "BenchmarkFixture") -> None:
"""Benchmark for cached_property cache miss."""

class Test:
Expand Down

0 comments on commit ccab7f4

Please sign in to comment.