def get_requirements_from_dist(dist: EggInfoDistribution, extras: Sequence[str]) -> List[str]: """Get requirements of a distribution, with given extras.""" extras_in_metadata = [] result = [] dep_map = dist._build_dep_map() for extra, reqs in dep_map.items(): reqs = [Requirement.from_pkg_requirement(r) for r in reqs] if not extra: # requirements without extras are always required. result.extend(r.as_line() for r in reqs) else: new_extra, _, marker = extra.partition(":") extras_in_metadata.append(new_extra.strip()) # Only include requirements that match one of extras. if not new_extra.strip() or safe_extra( new_extra.strip()) in extras: marker = Marker(marker) if marker else None for r in reqs: r.marker = marker result.append(r.as_line()) extras_not_found = [e for e in extras if e not in extras_in_metadata] if extras_not_found: warnings.warn(ExtrasError(extras_not_found)) return result
def get_sdist(egg_info: str) -> Optional[EggInfoDistribution]: """Get a distribution from egg_info directory.""" return EggInfoDistribution(egg_info) if egg_info else None