]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/models/target_python.py
2 from typing
import List
, Optional
, Tuple
4 from pip
._vendor
.packaging
.tags
import Tag
6 from pip
._internal
.utils
.compatibility_tags
import get_supported
, version_info_to_nodot
7 from pip
._internal
.utils
.misc
import normalize_version_info
13 Encapsulates the properties of a Python interpreter one is targeting
14 for a package install, download, etc.
18 "_given_py_version_info",
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,
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
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.
48 # Store the given py_version_info for when we call get_supported().
49 self
._given
_py
_version
_info
= py_version_info
51 if py_version_info
is None:
52 py_version_info
= sys
.version_info
[:3]
54 py_version_info
= normalize_version_info(py_version_info
)
56 py_version
= ".".join(map(str, py_version_info
[:2]))
59 self
.implementation
= implementation
60 self
.platforms
= platforms
61 self
.py_version
= py_version
62 self
.py_version_info
= py_version_info
64 # This is used to cache the return value of get_tags().
65 self
._valid
_tags
: Optional
[List
[Tag
]] = None
67 def format_given(self
) -> str:
69 Format the given, non-None attributes for display.
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
78 ("platforms", self
.platforms
),
79 ("version_info", display_version
),
81 ("implementation", self
.implementation
),
84 f
"{key}={value!r}" for key
, value
in key_values
if value
is not None
87 def get_tags(self
) -> List
[Tag
]:
89 Return the supported PEP 425 tags to check wheel candidates against.
91 The tags are returned in order of preference (most preferred first).
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:
100 version
= version_info_to_nodot(py_version_info
)
102 tags
= get_supported(
104 platforms
=self
.platforms
,
106 impl
=self
.implementation
,
108 self
._valid
_tags
= tags
110 return self
._valid
_tags