|
| 1 | +""" |
| 2 | +Small CLI script that accepts the path to a directory containing one |
| 3 | +or more wheel files. |
| 4 | +
|
| 5 | +Check that a wheel appropriately includes/excludes |
| 6 | +_distributor_init.py with the contents of that same |
| 7 | +file in the wheels repo. |
| 8 | +""" |
| 9 | + |
| 10 | +import sys |
| 11 | +import pathlib |
| 12 | +from zipfile import ZipFile |
| 13 | + |
| 14 | + |
| 15 | +def check_for_dist_init(input_dir): |
| 16 | + p = pathlib.Path(input_dir) |
| 17 | + wheel_files = p.glob('**/*.whl') |
| 18 | + for wheel_file in wheel_files: |
| 19 | + with ZipFile(wheel_file) as zipf: |
| 20 | + file_names = zipf.namelist() |
| 21 | + dist_init_found = 0 |
| 22 | + for file_name in file_names: |
| 23 | + if "_distributor_init.py" in file_name: |
| 24 | + dist_init_found += 1 |
| 25 | + with zipf.open(file_name) as actual_file: |
| 26 | + with open("_distributor_init.py", 'rb') as reference_file: |
| 27 | + # currently just MacOS and Windows should have _distributor_init.py |
| 28 | + # copied in from wheels repo; Linux should just have a generic |
| 29 | + # version of the file |
| 30 | + if "-macosx" in str(wheel_file) or "-win" in str(wheel_file): |
| 31 | + actual_content = actual_file.read() |
| 32 | + expected_content = reference_file.read() |
| 33 | + if not actual_content == expected_content: |
| 34 | + raise ValueError(f"Contents of _distributor_init.py incorrect for {wheel_file}") |
| 35 | + if not dist_init_found: |
| 36 | + raise FileNotFoundError(f"_distributor_init.py missing from {wheel_file}") |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + input_dir = sys.argv[1] |
| 40 | + check_for_dist_init(input_dir=input_dir) |
0 commit comments