Skip to content

Setuptools needs work #1

@ngoldbaum

Description

@ngoldbaum

If I patch brotlicffi like this:

diff --git a/setup.py b/setup.py
index e7176fe..77c55e2 100644
--- a/setup.py
+++ b/setup.py
@@ -93,12 +93,10 @@ setup(
     author_email="cory@lukasa.co.uk",

     setup_requires=[
-        "cffi>=1.0.0; python_version<'3.13'",
-        "cffi>=1.17.0; python_version>='3.13'",
+        "cffi @ git+https://github.com/python-cffi/cffi.git"
     ],
     install_requires=[
-        "cffi>=1.0.0; python_version<'3.13'",
-        "cffi>=1.17.0; python_version>='3.13'",
+        "cffi @ git+https://github.com/python-cffi/cffi.git"
     ],
     python_requires=">=3.8",
     cffi_modules=["src/brotlicffi/_build.py:ffi"],
diff --git a/src/brotlicffi/_build.py b/src/brotlicffi/_build.py
index 115be2e..afe5836 100644
--- a/src/brotlicffi/_build.py
+++ b/src/brotlicffi/_build.py
@@ -21,7 +21,8 @@ ffi.set_source(
        #include <brotli/encode.h>
     """,
     libraries=libraries,
-    include_dirs=["libbrotli/c", "libbrotli/c/include", "libbrotli/c/common"]
+    include_dirs=["libbrotli/c", "libbrotli/c/include", "libbrotli/c/common"],
+    define_macros=[("Py_LIMITED_API", "0x030f0000"), ('_Py_OPAQUE_PYOBJECT', '1')],
 )

 ffi.cdef("""

Then I'm able to build brotlicffi correctly on the GIL-enabled build. However, if I try with the free-threaded interpreter, I see errors like:

File "/private/var/folders/nk/yds4mlh97kg9qdq745g715rw0000gn/T/pip-build-env-3mhoegai/overlay/lib/python3.15t/site-packages/setuptools/command/bdist_wheel.py", line 285, in _validate_py_limited_api
          raise ValueError(
          ...<4 lines>...
          )
      ValueError: `py_limited_api='cp315'` not supported. `Py_LIMITED_API` is currently incompatible with `Py_GIL_DISABLED`. See https://github.com/python/cpython/issues/111506.

Which indicates to me that we need a fork of setuptools to work around this.

I can build brotlicffi on the free-threaded build if I haphazardly patch setuptools like so:

diff --git a/setuptools/command/bdist_wheel.py b/setuptools/command/bdist_wheel.py
index 3bdfa0b35..d2686469f 100644
--- a/setuptools/command/bdist_wheel.py
+++ b/setuptools/command/bdist_wheel.py
@@ -281,14 +281,6 @@ class bdist_wheel(Command):
         if not re.match(PY_LIMITED_API_PATTERN, self.py_limited_api):
             raise ValueError(f"py-limited-api must match '{PY_LIMITED_API_PATTERN}'")

-        if sysconfig.get_config_var("Py_GIL_DISABLED"):
-            raise ValueError(
-                f"`py_limited_api={self.py_limited_api!r}` not supported. "
-                "`Py_LIMITED_API` is currently incompatible with "
-                "`Py_GIL_DISABLED`. "
-                "See https://github.com/python/cpython/issues/111506."
-            )
-
     @property
     def wheel_dist_name(self) -> str:
         """Return distribution full name with - replaced with _"""
@@ -353,9 +345,6 @@ class bdist_wheel(Command):
             supported_tags = [
                 (t.interpreter, t.abi, plat_name) for t in tags.sys_tags()
             ]
-            assert tag in supported_tags, (
-                f"would build wheel with unsupported tag {tag}"
-            )
         return tag

     def run(self):

But I think deleting that assert is incorrect and instead we need to teach setuptools about the abi3.abi3t tag because the resulting wheel I get is tagged as abi3.cp315.

There's a comment in the setuptools tests in this repo that references pypa/setuptools#4810, which I think means the setuptools tests aren't actually testing anything?

Maybe using cffi would be a better way to test setuptools, since it seems to be easier to add C defines via CFFI's define_macros argument.

ping @kumaraditya303

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions