From 925e594744a487c1fab380b5fb44e3358e6f2ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 1 Oct 2023 18:48:12 +0200 Subject: [PATCH] Strip Requires-Dist metadata parsed from METADATA files These can contain a leading \n if the requirement was long and wrapped by email.message.EmailMessage.as_bytes(). --- src/pip/_internal/metadata/importlib/_dists.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/metadata/importlib/_dists.py b/src/pip/_internal/metadata/importlib/_dists.py index c4c508a26c9..ede12038495 100644 --- a/src/pip/_internal/metadata/importlib/_dists.py +++ b/src/pip/_internal/metadata/importlib/_dists.py @@ -218,7 +218,9 @@ def is_extra_provided(self, extra: str) -> bool: def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]: contexts: Sequence[Dict[str, str]] = [{"extra": e} for e in extras] for req_string in self.metadata.get_all("Requires-Dist", []): - req = Requirement(req_string) + # strip() because email.message.Message.get_all() may return a leading \n + # in case a long header was wrapped. + req = Requirement(req_string.strip()) if not req.marker: yield req elif not extras and req.marker.evaluate({"extra": ""}):