This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from tylerjereddy/treddy_verify_init
MAINT, CI: check _distributor_init.py contents
- Loading branch information
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Small CLI script that accepts the path to a directory containing one | ||
or more wheel files. | ||
Check that a wheel appropriately includes/excludes | ||
_distributor_init.py with the contents of that same | ||
file in the wheels repo. | ||
""" | ||
|
||
import sys | ||
import pathlib | ||
from zipfile import ZipFile | ||
|
||
|
||
def check_for_dist_init(input_dir): | ||
p = pathlib.Path(input_dir) | ||
wheel_files = p.glob('**/*.whl') | ||
for wheel_file in wheel_files: | ||
with ZipFile(wheel_file) as zipf: | ||
file_names = zipf.namelist() | ||
dist_init_found = 0 | ||
for file_name in file_names: | ||
if "_distributor_init.py" in file_name: | ||
dist_init_found += 1 | ||
with zipf.open(file_name) as actual_file: | ||
with open("_distributor_init.py", 'rb') as reference_file: | ||
# currently just MacOS and Windows should have _distributor_init.py | ||
# copied in from wheels repo; Linux should just have a generic | ||
# version of the file | ||
if "-macosx" in str(wheel_file) or "-win" in str(wheel_file): | ||
actual_content = actual_file.read() | ||
expected_content = reference_file.read() | ||
if not actual_content == expected_content: | ||
raise ValueError(f"Contents of _distributor_init.py incorrect for {wheel_file}") | ||
if not dist_init_found: | ||
raise FileNotFoundError(f"_distributor_init.py missing from {wheel_file}") | ||
|
||
if __name__ == "__main__": | ||
input_dir = sys.argv[1] | ||
check_for_dist_init(input_dir=input_dir) |