@@ -417,17 +417,27 @@ def build_wheel(
417417 config_settings : _ConfigSettings = None ,
418418 metadata_directory : StrPath | None = None ,
419419 ):
420- cmd = ['bdist_wheel' ]
421- if metadata_directory :
422- cmd .extend (['--dist-info-dir' , metadata_directory ])
423- with suppress_known_deprecation ():
424- return self ._build_with_temp_dir (
425- cmd ,
426- '.whl' ,
427- wheel_directory ,
428- config_settings ,
429- self ._arbitrary_args (config_settings ),
430- )
420+ def _build (cmd : list [str ]):
421+ with suppress_known_deprecation ():
422+ return self ._build_with_temp_dir (
423+ cmd ,
424+ '.whl' ,
425+ wheel_directory ,
426+ config_settings ,
427+ self ._arbitrary_args (config_settings ),
428+ )
429+
430+ if metadata_directory is None :
431+ return _build (['bdist_wheel' ])
432+
433+ try :
434+ return _build (['bdist_wheel' , '--dist-info-dir' , metadata_directory ])
435+ except SystemExit as ex : # pragma: nocover
436+ # pypa/setuptools#4683
437+ if "--dist-info-dir not recognized" not in str (ex ):
438+ raise
439+ _IncompatibleBdistWheel .emit ()
440+ return _build (['bdist_wheel' ])
431441
432442 def build_sdist (
433443 self , sdist_directory : StrPath , config_settings : _ConfigSettings = None
@@ -514,6 +524,17 @@ def run_setup(self, setup_script='setup.py'):
514524 sys .argv [0 ] = sys_argv_0
515525
516526
527+ class _IncompatibleBdistWheel (SetuptoolsDeprecationWarning ):
528+ _SUMMARY = "wheel.bdist_wheel is deprecated, please import it from setuptools"
529+ _DETAILS = """
530+ Ensure that any custom bdist_wheel implementation is a subclass of
531+ setuptools.command.bdist_wheel.bdist_wheel.
532+ """
533+ _DUE_DATE = (2025 , 10 , 15 )
534+ # Initially introduced in 2024/10/15, but maybe too disruptive to be enforced?
535+ _SEE_URL = "https://github.com/pypa/wheel/pull/631"
536+
537+
517538# The primary backend
518539_BACKEND = _BuildMetaBackend ()
519540
0 commit comments