Blame SOURCES/skip_yanked_releases.patch

70b653
From b97ef609100fbdd5895dab48cdab578dfeba396c Mon Sep 17 00:00:00 2001
70b653
From: Lumir Balhar <lbalhar@redhat.com>
70b653
Date: Fri, 10 Sep 2021 13:38:40 +0200
70b653
Subject: [PATCH 1/2] Implement handling of yanked_reason from the HTML anchor
70b653
70b653
---
70b653
 pip/index.py | 10 ++++++++--
70b653
 1 file changed, 8 insertions(+), 2 deletions(-)
70b653
70b653
diff --git a/pip/index.py b/pip/index.py
70b653
index f653f6e6a..ced52ce5a 100644
70b653
--- a/pip/index.py
70b653
+++ b/pip/index.py
70b653
@@ -865,7 +865,11 @@ class HTMLPage(object):
70b653
                 )
70b653
                 pyrequire = anchor.get('data-requires-python')
70b653
                 pyrequire = unescape(pyrequire) if pyrequire else None
70b653
-                yield Link(url, self, requires_python=pyrequire)
70b653
+                yanked_reason = anchor.get('data-yanked', default=None)
70b653
+                # Empty or valueless attribute are both parsed as empty string
70b653
+                if yanked_reason is not None:
70b653
+                    yanked_reason = unescape(yanked_reason)
70b653
+                yield Link(url, self, requires_python=pyrequire, yanked_reason=yanked_reason)
70b653
 
70b653
     _clean_re = re.compile(r'[^a-z0-9$&+,/:;=?@.#%_\\|-]', re.I)
70b653
 
70b653
@@ -879,7 +883,7 @@ class HTMLPage(object):
70b653
 
70b653
 class Link(object):
70b653
 
70b653
-    def __init__(self, url, comes_from=None, requires_python=None):
70b653
+    def __init__(self, url, comes_from=None, requires_python=None, yanked_reason=None):
70b653
         """
70b653
         Object representing a parsed link from https://pypi.python.org/simple/*
70b653
 
70b653
@@ -900,6 +904,8 @@ class Link(object):
70b653
         self.url = url
70b653
         self.comes_from = comes_from
70b653
         self.requires_python = requires_python if requires_python else None
70b653
+        self.yanked_reason = yanked_reason
70b653
+        self.yanked = yanked_reason is not None
70b653
 
70b653
     def __str__(self):
70b653
         if self.requires_python:
70b653
-- 
70b653
2.31.1
70b653
70b653
From d8dc6ee5d6809736dce43dc1e57d497f9ff91f26 Mon Sep 17 00:00:00 2001
70b653
From: Lumir Balhar <lbalhar@redhat.com>
70b653
Date: Fri, 10 Sep 2021 13:43:22 +0200
70b653
Subject: [PATCH 2/2] Skip all yanked candidates if possible
70b653
70b653
---
70b653
 pip/index.py | 21 +++++++++++++++++++++
70b653
 1 file changed, 21 insertions(+)
70b653
70b653
diff --git a/pip/index.py b/pip/index.py
70b653
index ced52ce5a..823bbaf7d 100644
70b653
--- a/pip/index.py
70b653
+++ b/pip/index.py
70b653
@@ -489,6 +489,27 @@ class PackageFinder(object):
70b653
         if applicable_candidates:
70b653
             best_candidate = max(applicable_candidates,
70b653
                                  key=self._candidate_sort_key)
70b653
+            # If we cannot find a non-yanked candidate,
70b653
+            # use the best one and print a warning about it.
70b653
+            # Otherwise, try to find another best candidate, ignoring
70b653
+            # all the yanked releases.
70b653
+            if getattr(best_candidate.location, "yanked", False):
70b653
+                nonyanked_candidates = [
70b653
+                    c for c in applicable_candidates
70b653
+                    if not getattr(c.location, "yanked", False)
70b653
+                ]
70b653
+
70b653
+                if set(nonyanked_candidates):
70b653
+                    best_candidate = max(nonyanked_candidates,
70b653
+                                         key=self._candidate_sort_key)
70b653
+                else:
70b653
+                    warning_message = (
70b653
+                        "WARNING: The candidate selected for download or install "
70b653
+                        "is a yanked version: '{}' candidate (version {} at {})"
70b653
+                    ).format(best_candidate.project, best_candidate.version, best_candidate.location)
70b653
+                    if best_candidate.location.yanked_reason:
70b653
+                        warning_message += "\nReason for being yanked: {}".format(best_candidate.location.yanked_reason)
70b653
+                    logger.warning(warning_message)
70b653
         else:
70b653
             best_candidate = None
70b653
 
70b653
-- 
70b653
2.31.1
70b653