Blame SOURCES/skip_yanked_releases.patch

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