Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.index.package_finder Namespace Reference

Data Structures

class  BestCandidateResult
 
class  CandidateEvaluator
 
class  CandidatePreferences
 
class  LinkEvaluator
 
class  LinkType
 
class  PackageFinder
 

Functions

bool _check_link_requires_python (Link link, Tuple[int, int, int] version_info, bool ignore_requires_python=False)
 
List[InstallationCandidatefilter_unallowed_hashes (List[InstallationCandidate] candidates, Optional[Hashes] hashes, str project_name)
 
int _find_name_version_sep (str fragment, str canonical_name)
 
Optional[str] _extract_version_from_fragment (str fragment, str canonical_name)
 

Variables

 logger = getLogger(__name__)
 
 BuildTag = Union[Tuple[()], Tuple[int, str]]
 
 CandidateSortingKey = Tuple[int, int, int, _BaseVersion, Optional[int], BuildTag]
 

Detailed Description

Routines related to PyPI, indexes

Function Documentation

◆ _check_link_requires_python()

bool _check_link_requires_python ( Link  link,
Tuple[int, int, int]  version_info,
bool   ignore_requires_python = False 
)
protected
Return whether the given Python version is compatible with a link's
"Requires-Python" value.

:param version_info: A 3-tuple of ints representing the Python
    major-minor-micro version to check.
:param ignore_requires_python: Whether to ignore the "Requires-Python"
    value if the given Python version isn't compatible.

Definition at line 51 of file package_finder.py.

55) -> bool:
56 """
57 Return whether the given Python version is compatible with a link's
58 "Requires-Python" value.
59
60 :param version_info: A 3-tuple of ints representing the Python
61 major-minor-micro version to check.
62 :param ignore_requires_python: Whether to ignore the "Requires-Python"
63 value if the given Python version isn't compatible.
64 """
65 try:
66 is_compatible = check_requires_python(
68 version_info=version_info,
69 )
72 "Ignoring invalid Requires-Python (%r) for link: %s",
74 link,
75 )
76 else:
77 if not is_compatible:
78 version = ".".join(map(str, version_info))
79 if not ignore_requires_python:
81 "Link requires a different Python (%s not in: %r): %s",
82 version,
84 link,
85 )
86 return False
87
89 "Ignoring failed Requires-Python check (%s not in: %r) for link: %s",
90 version,
92 link,
93 )
94
95 return True
96
97
for i

References i.

Referenced by LinkEvaluator.evaluate_link().

Here is the caller graph for this function:

◆ _extract_version_from_fragment()

Optional[str] _extract_version_from_fragment ( str  fragment,
str  canonical_name 
)
protected
Parse the version string from a <package>+<version> filename
"fragment" (stem) or egg fragment.

:param fragment: The string to parse. E.g. foo-2.1
:param canonical_name: The canonicalized name of the package this
    belongs to.

Definition at line 1014 of file package_finder.py.

1014def _extract_version_from_fragment(fragment: str, canonical_name: str) -> Optional[str]:
1015 """Parse the version string from a <package>+<version> filename
1016 "fragment" (stem) or egg fragment.
1017
1018 :param fragment: The string to parse. E.g. foo-2.1
1019 :param canonical_name: The canonicalized name of the package this
1020 belongs to.
1021 """
1022 try:
1023 version_start = _find_name_version_sep(fragment, canonical_name) + 1
1024 except ValueError:
1025 return None
1026 version = fragment[version_start:]
1027 if not version:
1028 return None
1029 return version

References pip._internal.index.package_finder._find_name_version_sep().

Referenced by LinkEvaluator.evaluate_link().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_name_version_sep()

int _find_name_version_sep ( str  fragment,
str  canonical_name 
)
protected
Find the separator's index based on the package's canonical name.

:param fragment: A <package>+<version> filename "fragment" (stem) or
    egg fragment.
:param canonical_name: The package's canonical name.

This function is needed since the canonicalized name does not necessarily
have the same length as the egg info's name part. An example::

>>> fragment = 'foo__bar-1.0'
>>> canonical_name = 'foo-bar'
>>> _find_name_version_sep(fragment, canonical_name)
8

Definition at line 988 of file package_finder.py.

988def _find_name_version_sep(fragment: str, canonical_name: str) -> int:
989 """Find the separator's index based on the package's canonical name.
990
991 :param fragment: A <package>+<version> filename "fragment" (stem) or
992 egg fragment.
993 :param canonical_name: The package's canonical name.
994
995 This function is needed since the canonicalized name does not necessarily
996 have the same length as the egg info's name part. An example::
997
998 >>> fragment = 'foo__bar-1.0'
999 >>> canonical_name = 'foo-bar'
1000 >>> _find_name_version_sep(fragment, canonical_name)
1001 8
1002 """
1003 # Project name and version must be separated by one single dash. Find all
1004 # occurrences of dashes; if the string in front of it matches the canonical
1005 # name, this is the one separating the name and version parts.
1006 for i, c in enumerate(fragment):
1007 if c != "-":
1008 continue
1009 if canonicalize_name(fragment[:i]) == canonical_name:
1010 return i
1011 raise ValueError(f"{fragment} does not match {canonical_name}")
1012
1013

References i.

Referenced by pip._internal.index.package_finder._extract_version_from_fragment().

Here is the caller graph for this function:

◆ filter_unallowed_hashes()

List[InstallationCandidate] filter_unallowed_hashes ( List[InstallationCandidate candidates,
Optional[Hashes hashes,
str  project_name 
)
Filter out candidates whose hashes aren't allowed, and return a new
list of candidates.

If at least one candidate has an allowed hash, then all candidates with
either an allowed hash or no hash specified are returned.  Otherwise,
the given candidates are returned.

Including the candidates with no hash specified when there is a match
allows a warning to be logged if there is a more preferred candidate
with no hash specified.  Returning all candidates in the case of no
matches lets pip report the hash of the candidate that would otherwise
have been installed (e.g. permitting the user to more easily update
their requirements file with the desired hash).

Definition at line 252 of file package_finder.py.

256) -> List[InstallationCandidate]:
257 """
258 Filter out candidates whose hashes aren't allowed, and return a new
259 list of candidates.
260
261 If at least one candidate has an allowed hash, then all candidates with
262 either an allowed hash or no hash specified are returned. Otherwise,
263 the given candidates are returned.
264
265 Including the candidates with no hash specified when there is a match
266 allows a warning to be logged if there is a more preferred candidate
267 with no hash specified. Returning all candidates in the case of no
268 matches lets pip report the hash of the candidate that would otherwise
269 have been installed (e.g. permitting the user to more easily update
270 their requirements file with the desired hash).
271 """
272 if not hashes:
274 "Given no hashes to check %s links for project %r: "
275 "discarding no candidates",
276 len(candidates),
277 project_name,
278 )
279 # Make sure we're not returning back the given value.
280 return list(candidates)
281
282 matches_or_no_digest = []
283 # Collect the non-matches for logging purposes.
284 non_matches = []
285 match_count = 0
286 for candidate in candidates:
287 link = candidate.link
288 if not link.has_hash:
289 pass
290 elif link.is_hash_allowed(hashes=hashes):
291 match_count += 1
292 else:
293 non_matches.append(candidate)
294 continue
295
297
298 if match_count:
299 filtered = matches_or_no_digest
300 else:
301 # Make sure we're not returning back the given value.
302 filtered = list(candidates)
303
304 if len(filtered) == len(candidates):
305 discard_message = "discarding no candidates"
306 else:
307 discard_message = "discarding {} non-matches:\n {}".format(
308 len(non_matches),
309 "\n ".join(str(candidate.link) for candidate in non_matches),
310 )
311
313 "Checked %s links for project %r against %s hashes "
314 "(%s matches, %s no digest): %s",
315 len(candidates),
316 project_name,
318 match_count,
319 len(matches_or_no_digest) - match_count,
320 discard_message,
321 )
322
323 return filtered
324
325

References i.

Referenced by CandidateEvaluator.get_applicable_candidates().

Here is the caller graph for this function:

Variable Documentation

◆ BuildTag

BuildTag = Union[Tuple[()], Tuple[int, str]]

Definition at line 47 of file package_finder.py.

◆ CandidateSortingKey

CandidateSortingKey = Tuple[int, int, int, _BaseVersion, Optional[int], BuildTag]

Definition at line 48 of file package_finder.py.

◆ logger

logger = getLogger(__name__)

Definition at line 45 of file package_finder.py.