Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.utils.wheel Namespace Reference

Functions

Tuple[str, Message] parse_wheel (ZipFile wheel_zip, str name)
 
str wheel_dist_info_dir (ZipFile source, str name)
 
bytes read_wheel_metadata_file (ZipFile source, str path)
 
Message wheel_metadata (ZipFile source, str dist_info_dir)
 
Tuple[int,...] wheel_version (Message wheel_data)
 
None check_compatibility (Tuple[int,...] version, str name)
 

Variables

tuple VERSION_COMPATIBLE = (1, 0)
 
 logger = logging.getLogger(__name__)
 

Detailed Description

Support functions for working with wheel files.

Function Documentation

◆ check_compatibility()

None check_compatibility ( Tuple[int, ...]  version,
str  name 
)
Raises errors or warns if called with an incompatible Wheel-Version.

pip should refuse to install a Wheel-Version that's a major series
ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
installing a version only minor version ahead (e.g 1.2 > 1.1).

version: a 2-tuple representing a Wheel-Version (Major, Minor)
name: name of wheel or package to raise exception about

:raises UnsupportedWheel: when an incompatible Wheel-Version is given

Definition at line 115 of file wheel.py.

115def check_compatibility(version: Tuple[int, ...], name: str) -> None:
116 """Raises errors or warns if called with an incompatible Wheel-Version.
117
118 pip should refuse to install a Wheel-Version that's a major series
119 ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
120 installing a version only minor version ahead (e.g 1.2 > 1.1).
121
122 version: a 2-tuple representing a Wheel-Version (Major, Minor)
123 name: name of wheel or package to raise exception about
124
125 :raises UnsupportedWheel: when an incompatible Wheel-Version is given
126 """
127 if version[0] > VERSION_COMPATIBLE[0]:
128 raise UnsupportedWheel(
129 "{}'s Wheel-Version ({}) is not compatible with this version "
130 "of pip".format(name, ".".join(map(str, version)))
131 )
132 elif version > VERSION_COMPATIBLE:
134 "Installing from a newer Wheel-Version (%s)",
135 ".".join(map(str, version)),
136 )
for i

References i.

Referenced by pip._internal.utils.wheel.parse_wheel().

Here is the caller graph for this function:

◆ parse_wheel()

Tuple[str, Message] parse_wheel ( ZipFile  wheel_zip,
str  name 
)
Extract information from the provided wheel, ensuring it meets basic
standards.

Returns the name of the .dist-info directory and the parsed WHEEL metadata.

Definition at line 20 of file wheel.py.

20def parse_wheel(wheel_zip: ZipFile, name: str) -> Tuple[str, Message]:
21 """Extract information from the provided wheel, ensuring it meets basic
22 standards.
23
24 Returns the name of the .dist-info directory and the parsed WHEEL metadata.
25 """
26 try:
27 info_dir = wheel_dist_info_dir(wheel_zip, name)
28 metadata = wheel_metadata(wheel_zip, info_dir)
29 version = wheel_version(metadata)
30 except UnsupportedWheel as e:
31 raise UnsupportedWheel("{} has an invalid wheel, {}".format(name, str(e)))
32
33 check_compatibility(version, name)
34
35 return info_dir, metadata
36
37

References pip._internal.utils.wheel.check_compatibility(), pip._internal.utils.wheel.wheel_dist_info_dir(), pip._internal.utils.wheel.wheel_metadata(), and pip._internal.utils.wheel.wheel_version().

Here is the call graph for this function:

◆ read_wheel_metadata_file()

bytes read_wheel_metadata_file ( ZipFile  source,
str  path 
)

Definition at line 71 of file wheel.py.

71def read_wheel_metadata_file(source: ZipFile, path: str) -> bytes:
72 try:
73 return source.read(path)
74 # BadZipFile for general corruption, KeyError for missing entry,
75 # and RuntimeError for password-protected files
76 except (BadZipFile, KeyError, RuntimeError) as e:
77 raise UnsupportedWheel(f"could not read {path!r} file: {e!r}")
78
79

References i.

◆ wheel_dist_info_dir()

str wheel_dist_info_dir ( ZipFile  source,
str  name 
)
Returns the name of the contained .dist-info directory.

Raises AssertionError or UnsupportedWheel if not found, >1 found, or
it doesn't match the provided name.

Definition at line 38 of file wheel.py.

38def wheel_dist_info_dir(source: ZipFile, name: str) -> str:
39 """Returns the name of the contained .dist-info directory.
40
41 Raises AssertionError or UnsupportedWheel if not found, >1 found, or
42 it doesn't match the provided name.
43 """
44 # Zip file path separators must be /
45 subdirs = {p.split("/", 1)[0] for p in source.namelist()}
46
47 info_dirs = [s for s in subdirs if s.endswith(".dist-info")]
48
49 if not info_dirs:
50 raise UnsupportedWheel(".dist-info directory not found")
51
52 if len(info_dirs) > 1:
53 raise UnsupportedWheel(
54 "multiple .dist-info directories found: {}".format(", ".join(info_dirs))
55 )
56
57 info_dir = info_dirs[0]
58
59 info_dir_name = canonicalize_name(info_dir)
60 canonical_name = canonicalize_name(name)
61 if not info_dir_name.startswith(canonical_name):
62 raise UnsupportedWheel(
63 ".dist-info directory {!r} does not start with {!r}".format(
64 info_dir, canonical_name
65 )
66 )
67
68 return info_dir
69
70

References i.

Referenced by pip._internal.utils.wheel.parse_wheel().

Here is the caller graph for this function:

◆ wheel_metadata()

Message wheel_metadata ( ZipFile  source,
str  dist_info_dir 
)
Return the WHEEL metadata of an extracted wheel, if possible.
Otherwise, raise UnsupportedWheel.

Definition at line 80 of file wheel.py.

80def wheel_metadata(source: ZipFile, dist_info_dir: str) -> Message:
81 """Return the WHEEL metadata of an extracted wheel, if possible.
82 Otherwise, raise UnsupportedWheel.
83 """
84 path = f"{dist_info_dir}/WHEEL"
85 # Zip file path separators must be /
86 wheel_contents = read_wheel_metadata_file(source, path)
87
88 try:
89 wheel_text = wheel_contents.decode()
90 except UnicodeDecodeError as e:
91 raise UnsupportedWheel(f"error decoding {path!r}: {e!r}")
92
93 # FeedParser (used by Parser) does not raise any exceptions. The returned
94 # message may have .defects populated, but for backwards-compatibility we
95 # currently ignore them.
96 return Parser().parsestr(wheel_text)
97
98

References i.

Referenced by pip._internal.utils.wheel.parse_wheel().

Here is the caller graph for this function:

◆ wheel_version()

Tuple[int, ...] wheel_version ( Message  wheel_data)
Given WHEEL metadata, return the parsed Wheel-Version.
Otherwise, raise UnsupportedWheel.

Definition at line 99 of file wheel.py.

99def wheel_version(wheel_data: Message) -> Tuple[int, ...]:
100 """Given WHEEL metadata, return the parsed Wheel-Version.
101 Otherwise, raise UnsupportedWheel.
102 """
103 version_text = wheel_data["Wheel-Version"]
104 if version_text is None:
105 raise UnsupportedWheel("WHEEL is missing Wheel-Version")
106
107 version = version_text.strip()
108
109 try:
110 return tuple(map(int, version.split(".")))
111 except ValueError:
112 raise UnsupportedWheel(f"invalid Wheel-Version: {version!r}")
113
114

References i.

Referenced by pip._internal.utils.wheel.parse_wheel().

Here is the caller graph for this function:

Variable Documentation

◆ logger

logger = logging.getLogger(__name__)

Definition at line 17 of file wheel.py.

◆ VERSION_COMPATIBLE

tuple VERSION_COMPATIBLE = (1, 0)

Definition at line 14 of file wheel.py.