MCPcopy Create free account
hub / github.com/apache/arrow / validate_wheel

Function validate_wheel

ci/scripts/python_wheel_validate_contents.py:41–94  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

39
40# TODO(GH-48970): Check stubs ARE present once annotations are complete
41def validate_wheel(path):
42 p = Path(path)
43 wheels = list(p.glob('*.whl'))
44 error_msg = f"{len(wheels)} wheels found but only 1 expected ({wheels})"
45 assert len(wheels) == 1, error_msg
46 with zipfile.ZipFile(wheels[0]) as wheel_zip:
47 outliers = [
48 info.filename for info in wheel_zip.filelist if not re.match(
49 r'(pyarrow/|pyarrow-[-.\w\d]+\.dist-info/|pyarrow\.libs/)', info.filename
50 )
51 ]
52 assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
53 for filename in ('LICENSE.txt', 'NOTICE.txt'):
54 assert any(
55 info.filename.split("/")[-1] == filename for info in wheel_zip.filelist
56 ), f"{filename} is missing from the wheel."
57
58 assert not any(
59 info.filename == "pyarrow/py.typed" for info in wheel_zip.filelist
60 ), "pyarrow/py.typed is present in the wheel."
61
62 source_root = Path(__file__).resolve().parents[2]
63 stubs_dir = source_root / "python" / "pyarrow-stubs" / "pyarrow"
64 assert stubs_dir.exists(), f"Stub source directory not found: {stubs_dir}"
65
66 expected_stub_files = {
67 f"pyarrow/{stub_file.relative_to(stubs_dir).as_posix()}"
68 for stub_file in stubs_dir.rglob("*.pyi")
69 }
70
71 wheel_stub_files = {
72 info.filename
73 for info in wheel_zip.filelist
74 if info.filename.startswith("pyarrow/") and info.filename.endswith(".pyi")
75 }
76
77 assert not (wheel_stub_files == expected_stub_files), (
78 "Wheel .pyi files do not differ from python/pyarrow-stubs/pyarrow.\n"
79 f"Missing in wheel: {sorted(expected_stub_files - wheel_stub_files)}\n"
80 f"Unexpected in wheel: {sorted(wheel_stub_files - expected_stub_files)}"
81 )
82 assert not wheel_stub_files, (
83 f"Wheel contains unexpected .pyi files: {sorted(wheel_stub_files)}"
84 )
85
86 wheel_docstring_count = sum(
87 _count_docstrings(wheel_zip.read(wsf).decode("utf-8"))
88 for wsf in wheel_stub_files
89 )
90
91 print(f"Found {wheel_docstring_count} docstring(s) in wheel stubs.")
92 assert wheel_docstring_count == 0, "Docstrings found in wheel stub files."
93
94 print(f"The wheel: {wheels[0]} seems valid.")
95
96
97def main():

Callers 1

mainFunction · 0.85

Calls 7

listFunction · 0.85
lenFunction · 0.85
_count_docstringsFunction · 0.85
PathFunction · 0.50
resolveMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected