comparison env/lib/python3.9/site-packages/pip/_internal/models/target_python.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import sys
2
3 from pip._internal.utils.compatibility_tags import get_supported, version_info_to_nodot
4 from pip._internal.utils.misc import normalize_version_info
5 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
6
7 if MYPY_CHECK_RUNNING:
8 from typing import List, Optional, Tuple
9
10 from pip._vendor.packaging.tags import Tag
11
12
13 class TargetPython:
14
15 """
16 Encapsulates the properties of a Python interpreter one is targeting
17 for a package install, download, etc.
18 """
19
20 __slots__ = [
21 "_given_py_version_info",
22 "abis",
23 "implementation",
24 "platforms",
25 "py_version",
26 "py_version_info",
27 "_valid_tags",
28 ]
29
30 def __init__(
31 self,
32 platforms=None, # type: Optional[List[str]]
33 py_version_info=None, # type: Optional[Tuple[int, ...]]
34 abis=None, # type: Optional[List[str]]
35 implementation=None, # type: Optional[str]
36 ):
37 # type: (...) -> None
38 """
39 :param platforms: A list of strings or None. If None, searches for
40 packages that are supported by the current system. Otherwise, will
41 find packages that can be built on the platforms passed in. These
42 packages will only be downloaded for distribution: they will
43 not be built locally.
44 :param py_version_info: An optional tuple of ints representing the
45 Python version information to use (e.g. `sys.version_info[:3]`).
46 This can have length 1, 2, or 3 when provided.
47 :param abis: A list of strings or None. This is passed to
48 compatibility_tags.py's get_supported() function as is.
49 :param implementation: A string or None. This is passed to
50 compatibility_tags.py's get_supported() function as is.
51 """
52 # Store the given py_version_info for when we call get_supported().
53 self._given_py_version_info = py_version_info
54
55 if py_version_info is None:
56 py_version_info = sys.version_info[:3]
57 else:
58 py_version_info = normalize_version_info(py_version_info)
59
60 py_version = '.'.join(map(str, py_version_info[:2]))
61
62 self.abis = abis
63 self.implementation = implementation
64 self.platforms = platforms
65 self.py_version = py_version
66 self.py_version_info = py_version_info
67
68 # This is used to cache the return value of get_tags().
69 self._valid_tags = None # type: Optional[List[Tag]]
70
71 def format_given(self):
72 # type: () -> str
73 """
74 Format the given, non-None attributes for display.
75 """
76 display_version = None
77 if self._given_py_version_info is not None:
78 display_version = '.'.join(
79 str(part) for part in self._given_py_version_info
80 )
81
82 key_values = [
83 ('platforms', self.platforms),
84 ('version_info', display_version),
85 ('abis', self.abis),
86 ('implementation', self.implementation),
87 ]
88 return ' '.join(
89 f'{key}={value!r}' for key, value in key_values
90 if value is not None
91 )
92
93 def get_tags(self):
94 # type: () -> List[Tag]
95 """
96 Return the supported PEP 425 tags to check wheel candidates against.
97
98 The tags are returned in order of preference (most preferred first).
99 """
100 if self._valid_tags is None:
101 # Pass versions=None if no py_version_info was given since
102 # versions=None uses special default logic.
103 py_version_info = self._given_py_version_info
104 if py_version_info is None:
105 version = None
106 else:
107 version = version_info_to_nodot(py_version_info)
108
109 tags = get_supported(
110 version=version,
111 platforms=self.platforms,
112 abis=self.abis,
113 impl=self.implementation,
114 )
115 self._valid_tags = tags
116
117 return self._valid_tags