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

Add support for free-threaded builds #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add support for free-threaded builds #70

wants to merge 1 commit into from

Conversation

hynek
Copy link
Owner

@hynek hynek commented Oct 8, 2024

fixes #67

@hynek hynek force-pushed the nogil branch 2 times, most recently from 358801e to 8285b78 Compare October 8, 2024 07:00
@hynek
Copy link
Owner Author

hynek commented Oct 8, 2024

@tacaswell so I tried to apply @minrk's changes and it's all red: https://github.com/hynek/argon2-cffi-bindings/actions/runs/11229954729

  • On Ubuntu, it tries and fails to build a CFFI wheel: https://github.com/hynek/argon2-cffi-bindings/actions/runs/11229954729/job/31216653852 (missing ffi.h!?). This might be possible to fix using cibuildwheel, but I won't bother until the next issue is fixed.

  • It seems like cffi is forcing the build into GIL-mode and then our logic to detect free-threading doesn't work and the build fails with "The limited API is not currently supported in the free-threaded build". I have no idea how to work around this?

cc @henryiii

@henryiii
Copy link

henryiii commented Oct 8, 2024

Can check tomorrow (ping me if I forget), but see python-cffi/cffi#104 in the meantime.

@hynek
Copy link
Owner Author

hynek commented Oct 8, 2024

Can check tomorrow (ping me if I forget),

Thanks!

but see python-cffi/cffi#104 in the meantime.

That's rather discouraging and implies the py_limited_api is a NOP? :(

@henryiii
Copy link

henryiii commented Oct 8, 2024

python-cffi/cffi#125 will be in the next version. Maybe try cffi from git?

@hynek
Copy link
Owner Author

hynek commented Oct 8, 2024

python-cffi/cffi#125 will be in the next version. Maybe try cffi from git?

At the danger of embarrassing myself, I have no idea how to do that: pin a git rev in build-requires?

And even worse, I haven't found an easy way to get a free-threaded Python on my Mac? For now, I'm extremely excited for indygreg/python-build-standalone#336 to ship.

@hynek
Copy link
Owner Author

hynek commented Oct 9, 2024

For reference: uv's issue tracking free-threaded installs: astral-sh/uv#8019

@minrk
Copy link

minrk commented Oct 9, 2024

pin a git rev in build-requires?

Yeah, you can do that. Perhaps not appropriate for publication, but you can use a git archive URL as a dependency:

[build-system]
requires = [
    "setuptools>=45",
    "setuptools_scm[toml]>=6.2",
    "wheel",
    "cffi>=1.0.1",
    # or a specific commit instead of HEAD
    "https://github.com/python-cffi/cffi/archive/HEAD.tar.gz; python_version >= '3.13'",
]

as done here.

@tacaswell
Copy link

Due to changes in setuptools (pypa/setuptools#4647) if you extend bdist_wheel from the wheel package the install will fail. I'm not 100% sure what the support windows of setuptools.wheel is vs the support window that argon2-cff-bindings needs of setuptools so I went with the defensive option. I'll also open a PR against the nogil branch.

diff --git a/setup.py b/setup.py
index 7510937..3a402e3 100644
--- a/setup.py
+++ b/setup.py
@@ -11,9 +11,12 @@ cmdclass = {}

 if platform.python_implementation() == "CPython":
     try:
-        import wheel.bdist_wheel
+        try:
+            from setuptools.command.bdist_wheel import bdist_wheel
+        except ImportError:
+            from wheel.bdist_wheel import bdist_wheel

-        class BDistWheel(wheel.bdist_wheel.bdist_wheel):
+        class BDistWheel(bdist_wheel):
             def finalize_options(self):
                 # Free-threaded CPython doesn't support limited API.
                 if sysconfig.get_config_var("Py_GIL_DISABLED"):
@@ -21,7 +24,7 @@ if platform.python_implementation() == "CPython":
                 else:
                     self.py_limited_api = f"cp3{sys.version_info[1]}"

-                wheel.bdist_wheel.bdist_wheel.finalize_options(self)
+                super().finalize_options()

         cmdclass["bdist_wheel"] = BDistWheel
     except ImportError:

@hynek hynek force-pushed the nogil branch 4 times, most recently from 7c6f0e6 to ffe98ff Compare October 15, 2024 08:55
Co-authored-by: Min RK <151929+minrk@users.noreply.github.com>
@tacaswell
Copy link

The floor on setuptools is 70.1, although I think upstream added a workaround so you can probably ignore my last comment.

@henryiii
Copy link

henryiii commented Oct 22, 2024

I'd still recommend using the correct one, the workaround is just to keep from blowing up for now, but wheel wants to get rid of it's API long term (it never had a public API, technically).

uv supports free-threaded now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Free-threaded builds fail
4 participants