diff --git a/backend/src/hatchling/metadata/spec.py b/backend/src/hatchling/metadata/spec.py index a83ea3db1..be1e21c28 100644 --- a/backend/src/hatchling/metadata/spec.py +++ b/backend/src/hatchling/metadata/spec.py @@ -169,24 +169,26 @@ def project_metadata_from_core_metadata(core_metadata: str) -> dict[str, Any]: continue markers = req.marker._markers # noqa: SLF001 + index = None for i, marker in enumerate(markers): if isinstance(marker, tuple): left, _, right = marker if left.value == 'extra': extra = right.value - del markers[i] # noqa: B909 - # If there was only one marker then there will be an unnecessary - # trailing semicolon in the string representation - if not markers: - req.marker = None - # Otherwise we need to remove the preceding `and` operation - else: - del markers[i - 1] - optional_dependencies.setdefault(extra, []).append(str(req)) + index = i break else: dependencies.append(str(req)) + if index is not None: + del markers[index] + # If there was only one marker then there will be an unnecessary + # trailing semicolon in the string representation + if not markers: + req.marker = None + # Otherwise we need to remove the preceding `and` operation + else: + del markers[index - 1] metadata['dependencies'] = dependencies