MCPcopy Create free account
hub / github.com/nodejs/node / parse_wheel_filename

Function parse_wheel_filename

tools/gyp/pylib/packaging/utils.py:103–143  ·  view source on GitHub ↗
(
    filename: str,
)

Source from the content-addressed store, hash-verified

101
102
103def parse_wheel_filename(
104 filename: str,
105) -> Tuple[NormalizedName, Version, BuildTag, FrozenSet[Tag]]:
106 if not filename.endswith(".whl"):
107 raise InvalidWheelFilename(
108 f"Invalid wheel filename (extension must be '.whl'): {filename}"
109 )
110
111 filename = filename[:-4]
112 dashes = filename.count("-")
113 if dashes not in (4, 5):
114 raise InvalidWheelFilename(
115 f"Invalid wheel filename (wrong number of parts): {filename}"
116 )
117
118 parts = filename.split("-", dashes - 2)
119 name_part = parts[0]
120 # See PEP 427 for the rules on escaping the project name.
121 if "__" in name_part or re.match(r"^[\w\d._]*$", name_part, re.UNICODE) is None:
122 raise InvalidWheelFilename(f"Invalid project name: {filename}")
123 name = canonicalize_name(name_part)
124
125 try:
126 version = Version(parts[1])
127 except InvalidVersion as e:
128 raise InvalidWheelFilename(
129 f"Invalid wheel filename (invalid version): {filename}"
130 ) from e
131
132 if dashes == 5:
133 build_part = parts[2]
134 build_match = _build_tag_regex.match(build_part)
135 if build_match is None:
136 raise InvalidWheelFilename(
137 f"Invalid build number: {build_part} in '{filename}'"
138 )
139 build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
140 else:
141 build = ()
142 tags = parse_tag(parts[-1])
143 return (name, version, build, tags)
144
145
146def parse_sdist_filename(filename: str) -> Tuple[NormalizedName, Version]:

Callers

nothing calls this directly

Calls 9

canonicalize_nameFunction · 0.85
intFunction · 0.85
parse_tagFunction · 0.85
VersionClass · 0.70
matchMethod · 0.65
castFunction · 0.50
countMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected