@@ -271,6 +271,8 @@ class StandardMetadata:
271271 keywords : list [str ] = dataclasses .field (default_factory = list )
272272 scripts : dict [str , str ] = dataclasses .field (default_factory = dict )
273273 gui_scripts : dict [str , str ] = dataclasses .field (default_factory = dict )
274+ import_names : list [str ] = dataclasses .field (default_factory = list )
275+ import_namespaces : list [str ] = dataclasses .field (default_factory = list )
274276 dynamic : list [Dynamic ] = dataclasses .field (default_factory = list )
275277 """
276278 This field is used to track dynamic fields. You can't set a field not in this list.
@@ -460,6 +462,14 @@ def from_pyproject( # noqa: C901
460462 project .get ("gui-scripts" , {}), "project.gui-scripts"
461463 )
462464 or {},
465+ import_names = pyproject .ensure_list (
466+ project .get ("import-names" , []), "project.import-names"
467+ )
468+ or [],
469+ import_namespaces = pyproject .ensure_list (
470+ project .get ("import-namespaces" , []), "project.import-namespaces"
471+ )
472+ or [],
463473 dynamic = dynamic ,
464474 dynamic_metadata = dynamic_metadata or [],
465475 metadata_version = metadata_version ,
@@ -504,6 +514,7 @@ def validate(self, *, warn: bool = True) -> None: # noqa: C901
504514 - ``license`` is an SPDX license expression if metadata_version >= 2.4
505515 - ``license_files`` is supported only for metadata_version >= 2.4
506516 - ``project_url`` can't contain keys over 32 characters
517+ - ``import-names(paces)`` is only supported on metadata_version >= 2.5
507518 """
508519 errors = ErrorCollector (collect_errors = self .all_errors )
509520
@@ -570,6 +581,20 @@ def validate(self, *, warn: bool = True) -> None: # noqa: C901
570581 msg = "{key} names cannot be more than 32 characters long"
571582 errors .config_error (msg , key = "project.urls" , got = name )
572583
584+ if (
585+ self .import_names
586+ and self .auto_metadata_version in constants .PRE_2_5_METADATA_VERSIONS
587+ ):
588+ msg = "{key} is only supported when emitting metadata version >= 2.5"
589+ errors .config_error (msg , key = "project.import_names" )
590+
591+ if (
592+ self .import_namespaces
593+ and self .auto_metadata_version in constants .PRE_2_5_METADATA_VERSIONS
594+ ):
595+ msg = "{key} is only supported when emitting metadata version >= 2.5"
596+ errors .config_error (msg , key = "project.import_namespaces" )
597+
573598 errors .finalize ("Metadata validation failed" )
574599
575600 def _write_metadata ( # noqa: C901
@@ -637,6 +662,10 @@ def _write_metadata( # noqa: C901
637662 if self .readme .content_type :
638663 smart_message ["Description-Content-Type" ] = self .readme .content_type
639664 smart_message .set_payload (self .readme .text )
665+ for import_name in self .import_names :
666+ smart_message ["Import-Name" ] = import_name
667+ for import_namespace in self .import_namespaces :
668+ smart_message ["Import-Namespace" ] = import_namespace
640669 # Core Metadata 2.2
641670 if self .auto_metadata_version != "2.1" :
642671 for field in self .dynamic_metadata :
0 commit comments