Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.packaging.version Namespace Reference

Data Structures

class  _BaseVersion
 
class  InvalidVersion
 
class  LegacyVersion
 
class  Version
 

Functions

Union["LegacyVersion", "Version"] parse (str version)
 
Iterator[str] _parse_version_parts (str s)
 
LegacyCmpKey _legacy_cmpkey (str version)
 
Optional[Tuple[str, int]] _parse_letter_version (str letter, Union[str, bytes, SupportsInt] number)
 
Optional[LocalType_parse_local_version (str local)
 
CmpKey _cmpkey (int epoch, Tuple[int,...] release, Optional[Tuple[str, int]] pre, Optional[Tuple[str, int]] post, Optional[Tuple[str, int]] dev, Optional[Tuple[SubLocalType]] local)
 

Variables

 InfiniteTypes = Union[InfinityType, NegativeInfinityType]
 
 PrePostDevType = Union[InfiniteTypes, Tuple[str, int]]
 
 SubLocalType = Union[InfiniteTypes, int, str]
 
 LocalType
 
 CmpKey
 
 LegacyCmpKey = Tuple[int, Tuple[str, ...]]
 
 VersionComparisonMethod
 
 _Version
 
 _legacy_version_component_re = re.compile(r"(\d+ | [a-z]+ | \.| -)", re.VERBOSE)
 
dict _legacy_version_replacement_map
 
str VERSION_PATTERN
 
 _local_version_separators = re.compile(r"[\._-]")
 

Function Documentation

◆ _cmpkey()

CmpKey _cmpkey ( int  epoch,
Tuple[int, ...]  release,
Optional[Tuple[str, int]]  pre,
Optional[Tuple[str, int]]  post,
Optional[Tuple[str, int]]  dev,
Optional[Tuple[SubLocalType]]  local 
)
protected

Definition at line 444 of file version.py.

451) -> CmpKey:
452
453 # When we compare a release version, we want to compare it with all of the
454 # trailing zeros removed. So we'll use a reverse the list, drop all the now
455 # leading zeros until we come to something non zero, then take the rest
456 # re-reverse it back into the correct order and make it a tuple and use
457 # that for our sorting key.
458 _release = tuple(
459 reversed(list(itertools.dropwhile(lambda x: x == 0, reversed(release))))
460 )
461
462 # We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0.
463 # We'll do this by abusing the pre segment, but we _only_ want to do this
464 # if there is not a pre or a post segment. If we have one of those then
465 # the normal sorting rules will handle this case correctly.
466 if pre is None and post is None and dev is not None:
467 _pre: PrePostDevType = NegativeInfinity
468 # Versions without a pre-release (except as noted above) should sort after
469 # those with one.
470 elif pre is None:
471 _pre = Infinity
472 else:
473 _pre = pre
474
475 # Versions without a post segment should sort before those with one.
476 if post is None:
477 _post: PrePostDevType = NegativeInfinity
478
479 else:
480 _post = post
481
482 # Versions without a development segment should sort after those with one.
483 if dev is None:
484 _dev: PrePostDevType = Infinity
485
486 else:
487 _dev = dev
488
489 if local is None:
490 # Versions without a local segment should sort before those with one.
491 _local: LocalType = NegativeInfinity
492 else:
493 # Versions with a local segment need that segment parsed to implement
494 # the sorting rules in PEP440.
495 # - Alpha numeric segments sort before numeric segments
496 # - Alpha numeric segments sort lexicographically
497 # - Numeric segments sort numerically
498 # - Shorter versions sort before longer versions when the prefixes
499 # match exactly
500 _local = tuple(
501 (i, "") if isinstance(i, int) else (NegativeInfinity, i) for i in local
502 )
503
504 return epoch, _release, _pre, _post, _dev, _local
for i

References i.

◆ _legacy_cmpkey()

LegacyCmpKey _legacy_cmpkey ( str  version)
protected

Definition at line 196 of file version.py.

196def _legacy_cmpkey(version: str) -> LegacyCmpKey:
197
198 # We hardcode an epoch of -1 here. A PEP 440 version can only have a epoch
199 # greater than or equal to 0. This will effectively put the LegacyVersion,
200 # which uses the defacto standard originally implemented by setuptools,
201 # as before all PEP 440 versions.
202 epoch = -1
203
204 # This scheme is taken from pkg_resources.parse_version setuptools prior to
205 # it's adoption of the packaging library.
206 parts: List[str] = []
207 for part in _parse_version_parts(version.lower()):
208 if part.startswith("*"):
209 # remove "-" before a prerelease tag
210 if part < "*final":
211 while parts and parts[-1] == "*final-":
212 parts.pop()
213
214 # remove trailing zeros from each series of numeric parts
215 while parts and parts[-1] == "00000000":
216 parts.pop()
217
218 parts.append(part)
219
220 return epoch, tuple(parts)
221
222
223# Deliberately not anchored to the start and end of the string, to make it
224# easier for 3rd party code to reuse

References pip._vendor.packaging.version._parse_version_parts(), and i.

Here is the call graph for this function:

◆ _parse_letter_version()

Optional[Tuple[str, int]] _parse_letter_version ( str  letter,
Union[str, bytes, SupportsInt]   number 
)
protected

Definition at line 393 of file version.py.

395) -> Optional[Tuple[str, int]]:
396
397 if letter:
398 # We consider there to be an implicit 0 in a pre-release if there is
399 # not a numeral associated with it.
400 if number is None:
401 number = 0
402
403 # We normalize any letters to their lower case form
404 letter = letter.lower()
405
406 # We consider some words to be alternate spellings of other words and
407 # in those cases we want to normalize the spellings to our preferred
408 # spelling.
409 if letter == "alpha":
410 letter = "a"
411 elif letter == "beta":
412 letter = "b"
413 elif letter in ["c", "pre", "preview"]:
414 letter = "rc"
415 elif letter in ["rev", "r"]:
416 letter = "post"
417
418 return letter, int(number)
419 if not letter and number:
420 # We assume if we are given a number, but we are not given a letter
421 # then this is using the implicit post release syntax (e.g. 1.0-1)
422 letter = "post"
423
424 return letter, int(number)
425
426 return None
427
428

References i.

◆ _parse_local_version()

Optional[LocalType] _parse_local_version ( str  local)
protected
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").

Definition at line 432 of file version.py.

432def _parse_local_version(local: str) -> Optional[LocalType]:
433 """
434 Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
435 """
436 if local is not None:
437 return tuple(
438 part.lower() if not part.isdigit() else int(part)
439 for part in _local_version_separators.split(local)
440 )
441 return None
442
443

References i.

◆ _parse_version_parts()

Iterator[str] _parse_version_parts ( str  s)
protected

Definition at line 179 of file version.py.

179def _parse_version_parts(s: str) -> Iterator[str]:
181 part = _legacy_version_replacement_map.get(part, part)
182
183 if not part or part == ".":
184 continue
185
186 if part[:1] in "0123456789":
187 # pad for numeric comparison
188 yield part.zfill(8)
189 else:
190 yield "*" + part
191
192 # ensure that alpha/beta/candidate are before final
193 yield "*final"
194
195

References i.

Referenced by pip._vendor.packaging.version._legacy_cmpkey().

Here is the caller graph for this function:

◆ parse()

Union["LegacyVersion", "Version"] parse ( str  version)
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.

Definition at line 42 of file version.py.

42def parse(version: str) -> Union["LegacyVersion", "Version"]:
43 """
44 Parse the given version string and return either a :class:`Version` object
45 or a :class:`LegacyVersion` object depending on if the given version is
46 a valid PEP 440 version or a legacy version.
47 """
48 try:
49 return Version(version)
50 except InvalidVersion:
51 return LegacyVersion(version)
52
53

Variable Documentation

◆ _legacy_version_component_re

_legacy_version_component_re = re.compile(r"(\d+ | [a-z]+ | \.| -)", re.VERBOSE)
protected

Definition at line 168 of file version.py.

◆ _legacy_version_replacement_map

dict _legacy_version_replacement_map
protected
Initial value:
1= {
2 "pre": "c",
3 "preview": "c",
4 "-": "final-",
5 "rc": "c",
6 "dev": "@",
7}

Definition at line 170 of file version.py.

◆ _local_version_separators

_local_version_separators = re.compile(r"[\._-]")
protected

Definition at line 429 of file version.py.

◆ _Version

_Version
protected
Initial value:
2 "_Version", ["epoch", "release", "dev", "pre", "post", "local"]
3)

Definition at line 37 of file version.py.

◆ CmpKey

CmpKey
Initial value:
1= Tuple[
2 int, Tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType
3]

Definition at line 29 of file version.py.

◆ InfiniteTypes

InfiniteTypes = Union[InfinityType, NegativeInfinityType]

Definition at line 15 of file version.py.

◆ LegacyCmpKey

LegacyCmpKey = Tuple[int, Tuple[str, ...]]

Definition at line 32 of file version.py.

◆ LocalType

LocalType
Initial value:
1= Union[
2 NegativeInfinityType,
3 Tuple[
4 Union[
5 SubLocalType,
6 Tuple[SubLocalType, str],
7 Tuple[NegativeInfinityType, SubLocalType],
8 ],
9 ...,
10 ],
11]

Definition at line 18 of file version.py.

◆ PrePostDevType

PrePostDevType = Union[InfiniteTypes, Tuple[str, int]]

Definition at line 16 of file version.py.

◆ SubLocalType

SubLocalType = Union[InfiniteTypes, int, str]

Definition at line 17 of file version.py.

◆ VERSION_PATTERN

str VERSION_PATTERN
Initial value:
1= r"""
2 v?
3 (?:
4 (?:(?P<epoch>[0-9]+)!)? # epoch
5 (?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
6 (?P<pre> # pre-release
7 [-_\.]?
8 (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
9 [-_\.]?
10 (?P<pre_n>[0-9]+)?
11 )?
12 (?P<post> # post release
13 (?:-(?P<post_n1>[0-9]+))
14 |
15 (?:
16 [-_\.]?
17 (?P<post_l>post|rev|r)
18 [-_\.]?
19 (?P<post_n2>[0-9]+)?
20 )
21 )?
22 (?P<dev> # dev release
23 [-_\.]?
24 (?P<dev_l>dev)
25 [-_\.]?
26 (?P<dev_n>[0-9]+)?
27 )?
28 )
29 (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
30"""

Definition at line 225 of file version.py.

◆ VersionComparisonMethod

VersionComparisonMethod
Initial value:
1= Callable[
2 [Union[CmpKey, LegacyCmpKey], Union[CmpKey, LegacyCmpKey]], bool
3]

Definition at line 33 of file version.py.