diff --git a/newsfragments/4684.bugfix.rst b/newsfragments/4684.bugfix.rst new file mode 100644 index 0000000000..40f554cccc --- /dev/null +++ b/newsfragments/4684.bugfix.rst @@ -0,0 +1,2 @@ +Add workaround for ``bdist_wheel --dist-info-dir`` errors +when customisation does not inherit from setuptools. diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index ecf434bbf3..e730a27f25 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -417,17 +417,27 @@ def build_wheel( config_settings: _ConfigSettings = None, metadata_directory: StrPath | None = None, ): - cmd = ['bdist_wheel'] - if metadata_directory: - cmd.extend(['--dist-info-dir', metadata_directory]) - with suppress_known_deprecation(): - return self._build_with_temp_dir( - cmd, - '.whl', - wheel_directory, - config_settings, - self._arbitrary_args(config_settings), - ) + def _build(cmd: list[str]): + with suppress_known_deprecation(): + return self._build_with_temp_dir( + cmd, + '.whl', + wheel_directory, + config_settings, + self._arbitrary_args(config_settings), + ) + + if metadata_directory is None: + return _build(['bdist_wheel']) + + try: + return _build(['bdist_wheel', '--dist-info-dir', metadata_directory]) + except SystemExit as ex: # pragma: nocover + # pypa/setuptools#4683 + if "--dist-info-dir not recognized" not in str(ex): + raise + _IncompatibleBdistWheel.emit() + return _build(['bdist_wheel']) def build_sdist( self, sdist_directory: StrPath, config_settings: _ConfigSettings = None @@ -514,6 +524,17 @@ def run_setup(self, setup_script='setup.py'): sys.argv[0] = sys_argv_0 +class _IncompatibleBdistWheel(SetuptoolsDeprecationWarning): + _SUMMARY = "wheel.bdist_wheel is deprecated, please import it from setuptools" + _DETAILS = """ + Ensure that any custom bdist_wheel implementation is a subclass of + setuptools.command.bdist_wheel.bdist_wheel. + """ + _DUE_DATE = (2025, 10, 15) + # Initially introduced in 2024/10/15, but maybe too disruptive to be enforced? + _SEE_URL = "https://github.com/pypa/wheel/pull/631" + + # The primary backend _BACKEND = _BuildMetaBackend()