diff --git a/newsfragments/4420.bugfix.rst b/newsfragments/4420.bugfix.rst new file mode 100644 index 0000000000..c5f75fcddb --- /dev/null +++ b/newsfragments/4420.bugfix.rst @@ -0,0 +1,2 @@ +Raises an exception when ``py_limited_api`` is used in a build with +``Py_GIL_DISABLED``. This is currently not supported (python/cpython#111506). diff --git a/setuptools/command/bdist_wheel.py b/setuptools/command/bdist_wheel.py index eca5568aad..8f06786659 100644 --- a/setuptools/command/bdist_wheel.py +++ b/setuptools/command/bdist_wheel.py @@ -274,10 +274,7 @@ def finalize_options(self) -> None: self.distribution.has_ext_modules() or self.distribution.has_c_libraries() ) - if self.py_limited_api and not re.match( - PY_LIMITED_API_PATTERN, self.py_limited_api - ): - raise ValueError(f"py-limited-api must match '{PY_LIMITED_API_PATTERN}'") + self._validate_py_limited_api() # Support legacy [wheel] section for setting universal wheel = self.distribution.get_option_dict("wheel") @@ -291,6 +288,21 @@ def finalize_options(self) -> None: if self.build_number is not None and not self.build_number[:1].isdigit(): raise ValueError("Build tag (build-number) must start with a digit.") + def _validate_py_limited_api(self) -> None: + if not self.py_limited_api: + return + + 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 " + f"`Py_GIL_DISABLED` ({sys.abiflags=!r}). " + "See https://github.com/python/cpython/issues/111506." + ) + @property def wheel_dist_name(self) -> str: """Return distribution full name with - replaced with _"""