comparison lib/python3.8/site-packages/pip/_internal/models/target_python.py @ 0:9e54283cc701 draft

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