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