Skip to content

Commit c3774cc

Browse files
authored
Merge pull request #6426 from pypa/restore-ignore-compat-finder
Add back ignore_compatibility option to pip package finder for comprehensive lock file generation
2 parents b7eed28 + e089238 commit c3774cc

File tree

3 files changed

+137
-11
lines changed

3 files changed

+137
-11
lines changed

news/6426.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restored ignore compatibility finder patch to enable comprehensive cross-platform hash collection in lock files.

pipenv/patched/pip/_internal/index/package_finder.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __init__(
135135
target_python: TargetPython,
136136
allow_yanked: bool,
137137
ignore_requires_python: Optional[bool] = None,
138+
ignore_compatibility: Optional[bool] = None,
138139
) -> None:
139140
"""
140141
:param project_name: The user supplied package name.
@@ -152,6 +153,8 @@ def __init__(
152153
:param ignore_requires_python: Whether to ignore incompatible
153154
PEP 503 "data-requires-python" values in HTML links. Defaults
154155
to False.
156+
:param ignore_compatibility: Whether to ignore
157+
compatibility of python versions and allow all versions of packages.
155158
"""
156159
if ignore_requires_python is None:
157160
ignore_requires_python = False
@@ -161,7 +164,7 @@ def __init__(
161164
self._ignore_requires_python = ignore_requires_python
162165
self._formats = formats
163166
self._target_python = target_python
164-
167+
self._ignore_compatibility = ignore_compatibility
165168
self.project_name = project_name
166169

167170
def evaluate_link(self, link: Link) -> Tuple[LinkType, str]:
@@ -191,10 +194,10 @@ def evaluate_link(self, link: Link) -> Tuple[LinkType, str]:
191194
LinkType.format_unsupported,
192195
f"unsupported archive format: {ext}",
193196
)
194-
if "binary" not in self._formats and ext == WHEEL_EXTENSION:
197+
if "binary" not in self._formats and ext == WHEEL_EXTENSION and not self._ignore_compatibility:
195198
reason = f"No binaries permitted for {self.project_name}"
196199
return (LinkType.format_unsupported, reason)
197-
if "macosx10" in link.path and ext == ".zip":
200+
if "macosx10" in link.path and ext == ".zip" and not self._ignore_compatibility:
198201
return (LinkType.format_unsupported, "macosx10 one")
199202
if ext == WHEEL_EXTENSION:
200203
try:
@@ -209,7 +212,7 @@ def evaluate_link(self, link: Link) -> Tuple[LinkType, str]:
209212
return (LinkType.different_project, reason)
210213

211214
supported_tags = self._target_python.get_unsorted_tags()
212-
if not wheel.supported(supported_tags):
215+
if not wheel.supported(supported_tags) and not self._ignore_compatibility:
213216
# Include the wheel's tags in the reason string to
214217
# simplify troubleshooting compatibility issues.
215218
file_tags = ", ".join(wheel.get_formatted_file_tags())
@@ -250,7 +253,7 @@ def evaluate_link(self, link: Link) -> Tuple[LinkType, str]:
250253
version_info=self._target_python.py_version_info,
251254
ignore_requires_python=self._ignore_requires_python,
252255
)
253-
if not supports_python:
256+
if not supports_python and not self._ignore_compatibility:
254257
reason = f"{version} Requires-Python {link.requires_python}"
255258
return (LinkType.requires_python_mismatch, reason)
256259

@@ -473,7 +476,11 @@ def get_applicable_candidates(
473476

474477
return sorted(filtered_applicable_candidates, key=self._sort_key)
475478

476-
def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
479+
def _sort_key(
480+
self,
481+
candidate: InstallationCandidate,
482+
ignore_compatibility: bool = True,
483+
) -> CandidateSortingKey:
477484
"""
478485
Function to pass as the `key` argument to a call to sorted() to sort
479486
InstallationCandidates by preference.
@@ -518,10 +525,12 @@ def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
518525
)
519526
)
520527
except ValueError:
521-
raise UnsupportedWheel(
522-
f"{wheel.filename} is not a supported wheel for this platform. It "
523-
"can't be sorted."
524-
)
528+
if not ignore_compatibility:
529+
raise UnsupportedWheel(
530+
f"{wheel.filename} is not a supported wheel for this platform. It "
531+
"can't be sorted."
532+
)
533+
pri = -support_num
525534
if self._prefer_binary:
526535
binary_preference = 1
527536
build_tag = wheel.build_tag
@@ -584,6 +593,7 @@ def __init__(
584593
format_control: Optional[FormatControl] = None,
585594
candidate_prefs: Optional[CandidatePreferences] = None,
586595
ignore_requires_python: Optional[bool] = None,
596+
ignore_compatibility: Optional[bool] = False,
587597
) -> None:
588598
"""
589599
This constructor is primarily meant to be used by the create() class
@@ -605,7 +615,7 @@ def __init__(
605615
self._ignore_requires_python = ignore_requires_python
606616
self._link_collector = link_collector
607617
self._target_python = target_python
608-
618+
self._ignore_compatibility = ignore_compatibility
609619
self.format_control = format_control
610620

611621
# These are boring links that have already been logged somehow.
@@ -730,6 +740,7 @@ def make_link_evaluator(self, project_name: str) -> LinkEvaluator:
730740
target_python=self._target_python,
731741
allow_yanked=self._allow_yanked,
732742
ignore_requires_python=self._ignore_requires_python,
743+
ignore_compatibility=self._ignore_compatibility,
733744
)
734745

735746
def _sort_links(self, links: Iterable[Link]) -> List[Link]:
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
--- a/pipenv/patched/pip/_internal/index/package_finder.py
2+
+++ b/pipenv/patched/pip/_internal/index/package_finder.py
3+
@@ -135,6 +135,7 @@ class LinkEvaluator:
4+
target_python: TargetPython,
5+
allow_yanked: bool,
6+
ignore_requires_python: Optional[bool] = None,
7+
+ ignore_compatibility: Optional[bool] = None,
8+
) -> None:
9+
"""
10+
:param project_name: The user supplied package name.
11+
@@ -152,6 +153,8 @@ class LinkEvaluator:
12+
:param ignore_requires_python: Whether to ignore incompatible
13+
PEP 503 "data-requires-python" values in HTML links. Defaults
14+
to False.
15+
+ :param ignore_compatibility: Whether to ignore
16+
+ compatibility of python versions and allow all versions of packages.
17+
"""
18+
if ignore_requires_python is None:
19+
ignore_requires_python = False
20+
@@ -161,7 +164,7 @@ class LinkEvaluator:
21+
self._ignore_requires_python = ignore_requires_python
22+
self._formats = formats
23+
self._target_python = target_python
24+
-
25+
+ self._ignore_compatibility = ignore_compatibility
26+
self.project_name = project_name
27+
28+
def evaluate_link(self, link: Link) -> Tuple[LinkType, str]:
29+
@@ -191,10 +194,10 @@ class LinkEvaluator:
30+
LinkType.format_unsupported,
31+
f"unsupported archive format: {ext}",
32+
)
33+
- if "binary" not in self._formats and ext == WHEEL_EXTENSION:
34+
+ if "binary" not in self._formats and ext == WHEEL_EXTENSION and not self._ignore_compatibility:
35+
reason = f"No binaries permitted for {self.project_name}"
36+
return (LinkType.format_unsupported, reason)
37+
- if "macosx10" in link.path and ext == ".zip":
38+
+ if "macosx10" in link.path and ext == ".zip" and not self._ignore_compatibility:
39+
return (LinkType.format_unsupported, "macosx10 one")
40+
if ext == WHEEL_EXTENSION:
41+
try:
42+
@@ -209,7 +212,7 @@ class LinkEvaluator:
43+
return (LinkType.different_project, reason)
44+
45+
supported_tags = self._target_python.get_unsorted_tags()
46+
- if not wheel.supported(supported_tags):
47+
+ if not wheel.supported(supported_tags) and not self._ignore_compatibility:
48+
# Include the wheel's tags in the reason string to
49+
# simplify troubleshooting compatibility issues.
50+
file_tags = ", ".join(wheel.get_formatted_file_tags())
51+
@@ -250,7 +253,7 @@ class LinkEvaluator:
52+
version_info=self._target_python.py_version_info,
53+
ignore_requires_python=self._ignore_requires_python,
54+
)
55+
- if not supports_python:
56+
+ if not supports_python and not self._ignore_compatibility:
57+
reason = f"{version} Requires-Python {link.requires_python}"
58+
return (LinkType.requires_python_mismatch, reason)
59+
60+
@@ -473,7 +476,11 @@ class PackageFinder:
61+
62+
return sorted(filtered_applicable_candidates, key=self._sort_key)
63+
64+
- def _sort_key(self, candidate: InstallationCandidate) -> CandidateSortingKey:
65+
+ def _sort_key(
66+
+ self,
67+
+ candidate: InstallationCandidate,
68+
+ ignore_compatibility: bool = True,
69+
+ ) -> CandidateSortingKey:
70+
"""
71+
Function to pass as the `key` argument to a call to sorted() to sort
72+
InstallationCandidates by preference.
73+
@@ -518,10 +525,12 @@ class PackageFinder:
74+
)
75+
)
76+
except ValueError:
77+
- raise UnsupportedWheel(
78+
- f"{wheel.filename} is not a supported wheel for this platform. It "
79+
- "can't be sorted."
80+
- )
81+
+ if not ignore_compatibility:
82+
+ raise UnsupportedWheel(
83+
+ f"{wheel.filename} is not a supported wheel for this platform. It "
84+
+ "can't be sorted."
85+
+ )
86+
+ pri = -support_num
87+
if self._prefer_binary:
88+
binary_preference = 1
89+
build_tag = wheel.build_tag
90+
@@ -584,6 +593,7 @@ class PackageFinder:
91+
format_control: Optional[FormatControl] = None,
92+
candidate_prefs: Optional[CandidatePreferences] = None,
93+
ignore_requires_python: Optional[bool] = None,
94+
+ ignore_compatibility: Optional[bool] = False,
95+
) -> None:
96+
"""
97+
This constructor is primarily meant to be used by the create() class
98+
@@ -605,7 +615,7 @@ class PackageFinder:
99+
self._ignore_requires_python = ignore_requires_python
100+
self._link_collector = link_collector
101+
self._target_python = target_python
102+
-
103+
+ self._ignore_compatibility = ignore_compatibility
104+
self.format_control = format_control
105+
106+
# These are boring links that have already been logged somehow.
107+
@@ -730,6 +740,7 @@ class PackageFinder:
108+
target_python=self._target_python,
109+
allow_yanked=self._allow_yanked,
110+
ignore_requires_python=self._ignore_requires_python,
111+
+ ignore_compatibility=self._ignore_compatibility,
112+
)
113+
114+
def _sort_links(self, links: Iterable[Link]) -> List[Link]:

0 commit comments

Comments
 (0)