From ab181811aeb8014017a0404d729d32fe1245f927 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Mon, 18 Jan 2021 05:54:04 +0800 Subject: [PATCH] Use str to pass versions to avoid debundling issue --- news/9348.bugfix.rst | 2 ++ src/pip/_internal/req/req_install.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 news/9348.bugfix.rst diff --git a/news/9348.bugfix.rst b/news/9348.bugfix.rst new file mode 100644 index 00000000000..99e673954c9 --- /dev/null +++ b/news/9348.bugfix.rst @@ -0,0 +1,2 @@ +Avoid parsing version to make the version check more robust against lousily +debundled downstream distributions. diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 11d000df503..87b5b03f3b3 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -432,8 +432,16 @@ def check_if_exists(self, use_user_site): if not existing_dist: return - existing_version = existing_dist.parsed_version - if not self.req.specifier.contains(existing_version, prereleases=True): + # pkg_resouces may contain a different copy of packaging.version from + # pip in if the downstream distributor does a poor job debundling pip. + # We avoid existing_dist.parsed_version and let SpecifierSet.contains + # parses the version instead. + existing_version = existing_dist.version + version_compatible = ( + existing_version is not None and + self.req.specifier.contains(existing_version, prereleases=True) + ) + if not version_compatible: self.satisfied_by = None if use_user_site: if dist_in_usersite(existing_dist):