@@ -317,6 +317,7 @@ def _create_dist_info(staging_dir: Path, metadata: dict, project_dir: Path) -> P
317317 return dist_info_dir
318318
319319
320+
320321# PEP 517 Hooks
321322
322323def get_requires_for_build_wheel (config_settings : Optional [dict ] = None ) -> list :
@@ -333,6 +334,34 @@ def get_requires_for_build_sdist(config_settings: Optional[dict] = None) -> list
333334 return []
334335
335336
337+ def prepare_metadata_for_build_wheel (
338+ metadata_directory : str ,
339+ config_settings : Optional [dict ] = None ,
340+ ) -> str :
341+ """
342+ PEP 517 hook: Prepare wheel metadata without building the full wheel.
343+
344+ Creates a .dist-info directory inside metadata_directory containing only
345+ METADATA. The WHEEL file is intentionally omitted: wheel tags depend on
346+ Conan's VirtualBuildEnv and cannot be computed reliably at this stage.
347+
348+ Returns the name of the created directory.
349+ """
350+ metadata_dir = Path (metadata_directory )
351+ metadata_dir .mkdir (parents = True , exist_ok = True )
352+
353+ source_dir = Path .cwd ()
354+ project_metadata = _get_project_metadata (source_dir )
355+ _resolve_version (project_metadata , source_dir )
356+
357+ name = _normalize_name (project_metadata .get ("name" , "unknown" ))
358+ version = project_metadata .get ("version" , "0.0.0" )
359+ print (f"Preparing metadata for { name } { version } ..." , flush = True )
360+
361+ dist_info_dir = _create_dist_info (metadata_dir , project_metadata , source_dir )
362+ return dist_info_dir .name
363+
364+
336365def build_wheel (
337366 wheel_directory : str ,
338367 config_settings : Optional [dict ] = None ,
@@ -341,14 +370,12 @@ def build_wheel(
341370 """
342371 PEP 517 hook: Build a wheel from the source tree.
343372
344- Note: prepare_metadata_for_build_wheel is not implemented, so
345- metadata_directory is ignored if provided.
373+ When metadata_directory is provided its contents (METADATA, license files,
374+ and any extra entries) are copied into the wheel unchanged. The WHEEL file
375+ and RECORD are still written by distlib during wheel packaging. Wheel tags
376+ are always recomputed inside VirtualBuildEnv.
346377 """
347378
348- if metadata_directory is not None :
349- print (f"WARNING: metadata_directory provided: '{ metadata_directory } ' - " \
350- "backend will ignore/recreate dist-info." )
351-
352379 wheel_dir = Path (wheel_directory )
353380 wheel_dir .mkdir (parents = True , exist_ok = True )
354381
@@ -370,6 +397,7 @@ def build_wheel(
370397 version ,
371398 project_metadata ,
372399 config ,
400+ metadata_directory ,
373401 )
374402
375403
@@ -426,6 +454,7 @@ def _do_build_wheel(
426454 version : str ,
427455 project_metadata : dict ,
428456 config : dict ,
457+ metadata_directory : Optional [str ] = None ,
429458) -> str :
430459 """Internal function that performs the actual wheel build."""
431460
@@ -539,8 +568,12 @@ def _do_build_wheel(
539568 # Copy shared libs from Conan's runtime_deploy to the wheel layout.
540569 move_deploy_to_wheel (runtime_deploy_dir , staging_dir )
541570
542- # Create dist-info
543- _create_dist_info (staging_dir , project_metadata , source_dir )
571+ # Create dist-info (or reuse the one prepared by prepare_metadata_for_build_wheel)
572+ if metadata_directory is not None :
573+ src = Path (metadata_directory ) # PEP 517: metadata_directory is the .dist-info path itself
574+ shutil .copytree (src , staging_dir / src .name , dirs_exist_ok = True )
575+ else :
576+ _create_dist_info (staging_dir , project_metadata , source_dir )
544577
545578 # Build wheel using distlib. Apply Conan's buildenv to get cross-compile
546579 # wheel tags from [buildenv]
0 commit comments