Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for the free-threaded build of CPython 3.13 #84

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

lysnikolaou
Copy link

What do these changes do?

  • Add a matrix config for free-threaded Python to run tests with it.
  • Change configuration to correctly build wheels under the free-threaded build.

Are there changes in behavior for the user?

No.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Dec 20, 2024
pyproject.toml Outdated Show resolved Hide resolved
MANIFEST.in Outdated Show resolved Hide resolved
src/propcache/_helpers_c.pyx Show resolved Hide resolved
scripts/cibw_before_build.sh Outdated Show resolved Hide resolved
@lysnikolaou
Copy link
Author

Hey folks, thanks for all the review and sorry for the extended delay here, I was out on PTO. I've addressed most of the comments around adding some TODOs and replied to the rest.

Copy link

codspeed-hq bot commented Jan 13, 2025

CodSpeed Performance Report

Merging #84 will degrade performances by 8.05%

Comparing lysnikolaou:freethreading-support (2bbb0f7) with master (b8aeb2f)

Summary

❌ 1 (👁 1) regressions
✅ 3 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
👁 test_under_cached_property_cache_hit 67.9 µs 73.8 µs -8.05%

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.03%. Comparing base (b8aeb2f) to head (2bbb0f7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
+ Coverage   89.02%   89.03%   +0.01%     
==========================================
  Files          18       18              
  Lines         738      739       +1     
  Branches       75       75              
==========================================
+ Hits          657      658       +1     
  Misses         63       63              
  Partials       18       18              
Flag Coverage Δ
CI-GHA 89.03% <100.00%> (+0.01%) ⬆️
MyPy 78.53% <100.00%> (+0.03%) ⬆️
OS-Linux 99.44% <100.00%> (ø)
OS-Windows 95.41% <ø> (ø)
OS-macOS 95.86% <100.00%> (ø)
Py-3.10.11 95.59% <100.00%> (ø)
Py-3.10.16 97.79% <100.00%> (ø)
Py-3.11.11 97.79% <100.00%> (ø)
Py-3.11.9 95.59% <100.00%> (ø)
Py-3.12.8 97.79% <100.00%> (ø)
Py-3.13.1 97.55% <ø> (-0.25%) ⬇️
Py-3.9.13 95.58% <100.00%> (ø)
Py-3.9.21 97.79% <100.00%> (ø)
Py-pypy7.3.16 97.23% <ø> (ø)
Py-pypy7.3.17 97.24% <ø> (ø)
VM-macos-latest 95.86% <100.00%> (ø)
VM-ubuntu-latest 99.44% <100.00%> (ø)
VM-windows-latest 95.41% <ø> (ø)
pytest 99.44% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lysnikolaou
Copy link
Author

Gentle ping on this. Is there anything I can do to move it forward?

@@ -372,7 +372,8 @@ def get_requires_for_build_wheel(
)

c_ext_build_deps = [] if is_pure_python_build else [
'Cython ~= 3.0.0; python_version >= "3.12"',
'Cython == 3.1.0a1; python_version >= "3.13"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the performance regression is coming from 3.1.0a1.

We should only use 3.1.0a1 if its the free-threading 3.13 so this doesn't affect the current 3.13 production builds

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the performance regression is coming from 3.1.0a1.

We should only use 3.1.0a1 if its the free-threading 3.13 so this doesn't affect the current 3.13 production builds

That's not very easy to do if we continue using a constraint file for Cython since there's no marker for the free-threaded build. It seems though that we could remove the contraints from a couple of places:

  • When building sdists and pure python wheels: Cython is probably not needed there.
  • For the configuration environment in cibuildwheel: Can be removed, since the Cython versions that ends up being installed is the one specified in the build backend.

I'm not sure how we would do that for the test requirements though, since Cython is needed there as well. We would have to use something more complicated to be able to install the correct version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webknjaz would you kindly offer some guidance here?

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lysnikolaou sorry for the delay

I think this is good to go once https://github.com/aio-libs/propcache/pull/84/files#r1925771536 is addressed

c_ext_build_deps = []
elif sysconfig.get_config_var("Py_GIL_DISABLED"):
# TODO: Remove when there's a Cython final with free-threading support
c_ext_build_deps = ['Cython == 3.1.0a1']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not compat?

Suggested change
c_ext_build_deps = ['Cython == 3.1.0a1']
c_ext_build_deps = ['Cython ~= 3.1.0a1']

It'd allow other versions below 3.1.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work for sure. There's still the problem described here however.

src/propcache/_helpers_c.pyx Show resolved Hide resolved
Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest waiting for non-alpha Cython release. A Release Candidate is ok, but alpha is not.

@Dreamsorcerer
Copy link
Member

I would suggest waiting for non-alpha Cython release. A Release Candidate is ok, but alpha is not.

It's a compile-time experimental feature on cpython, I don't think anybody is expecting us to have a rock solid supported implementation. It's essentially a preview release at this point, so alpha is fine at this stage (and the only thing we can offer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants