def merge_marker(requirement: Requirement, marker: str) -> None: """Merge the target marker str with the requirement markers""" if not requirement.marker: requirement.marker = Marker(marker) return old_marker = requirement.marker if "or" in old_marker._markers: new_marker = Marker(f"({old_marker}) and {marker}") else: new_marker = Marker(f"{old_marker} and {marker}") requirement.marker = new_marker
def requires_extra(self) -> Dict[str, List[str]]: """For PKG-INFO metadata""" if not self.optional_dependencies: return {} result = {} for name, reqs in self.optional_dependencies.items(): current = result[name] = [] for r in reqs: parsed = Requirement(r) merge_marker(parsed, f"extra == {name!r}") current.append(str(parsed)) return result