MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / check_wheel

Function check_wheel

scripts/utils/check-dist.py:211–233  ·  view source on GitHub ↗
(path: Path, package: str, pyproject: dict[str, Any], committed: dict[str, Committed])

Source from the content-addressed store, hash-verified

209
210
211def check_wheel(path: Path, package: str, pyproject: dict[str, Any], committed: dict[str, Committed]) -> bytes:
212 info = f"{package}.dist-info/"
213 metadata, tags, record = info + "METADATA", info + "WHEEL", info + "RECORD"
214 folders = tuple(f"{folder}/" for folder in pyproject["tool"]["hatch"]["build"]["targets"]["wheel"]["packages"])
215 allowed = {name.removeprefix("src/"): name for name in committed if name.startswith(folders)}
216 allowed |= {f"{info}licenses/{name}": name for name in committed if re.fullmatch(LICENSE, name)}
217 contents = check_files(path.name, read_wheel(path), committed, allowed, {*allowed, metadata, tags, record})
218
219 (hatchling,) = (dep for dep in pyproject["build-system"]["requires"] if dep.startswith("hatchling=="))
220 generator = hatchling.replace("==", " ")
221 expected_tags = f"Wheel-Version: 1.0\nGenerator: {generator}\nRoot-Is-Purelib: true\nTag: py3-none-any\n"
222 if contents.get(tags) != expected_tags.encode():
223 problems.append(f"{path.name}: {tags} is not what {generator} writes")
224
225 lines = [f"{record},,", ""]
226 for name, data in contents.items():
227 if name != record:
228 digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode()
229 lines.append(f"{name},sha256={digest},{len(data)}")
230 if sorted(contents.get(record, b"").decode().split("\n")) != sorted(lines):
231 problems.append(f"{path.name}: {record} does not describe its files")
232
233 return contents.get(metadata, b"")
234
235
236def check_sdist(path: Path, package: str, committed: dict[str, Committed]) -> bytes:

Callers 1

mainFunction · 0.85

Calls 5

check_filesFunction · 0.85
read_wheelFunction · 0.85
decodeMethod · 0.80
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected