Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit dbb2bb9

Browse files
committed
MAINT, CI: check _distributor_init.py contents
* following on from continued problems reported here: scipy/scipy#15050 * draft in code to check that MacOS wheels get the same `_distributor_init.py` as the one present in the wheels repo, rather than the generic nearly-empty copy actually present in the `1.7.3` release * we've had two pull requests about this and it slipped through into a release despite 3 sets of eyes so need to be careful here; I'd like to the test script added here failing for MacOS in CI like it does locally, before attempting a fix * this is likely still wip, since relative paths/directories can be confusing to predict in the wheels/multibuild control flow, which also flushes in and out of containers I think, etc. (this probably contributed to the original problem) * the script did seem to work in a quick local check though, complaining about our new MacOS file inclusion, but happy with the long-standing windows wheel inclusion for dirs containing wheels for each OS type: `python verify_init.py /Users/treddy/rough_work/scipy/release_173/release/installers/windows` `python verify_init.py /Users/treddy/rough_work/scipy/release_173/release/installers/linux` `python verify_init.py /Users/treddy/rough_work/scipy/release_173/release/installers/mac` ``` Traceback (most recent call last): File "verify_init.py", line 40, in <module> check_for_dist_init(input_dir=input_dir) File "verify_init.py", line 34, in check_for_dist_init raise ValueError(f"Contents of _distributor_init.py incorrect for {wheel_file}") ValueError: Contents of _distributor_init.py incorrect for /Users/treddy/rough_work/scipy/release_173/release/installers/mac/scipy-1.7.3-cp39-cp39-macosx_10_9_x86_64.whl ```
1 parent f1d2caa commit dbb2bb9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

appveyor.yml

+2
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ test_script:
198198
- python ..\run_scipy_tests.py %TEST_MODE% -- -n6 --junitxml=%cd%\junit-results.xml -rfEX
199199

200200
after_test:
201+
- ls ..\scipy\dist
202+
- python verify_init.py ..\scipy\dist
201203
# Upload test results to Appveyor
202204
- ps: |
203205
If (Test-Path .\junit-results.xml) {

azure-posix.yml

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ jobs:
8888
displayName: "Rename MacOS arm64 wheels for version 12.0 minimum"
8989
condition: eq(variables['PLAT'], 'arm64')
9090
91+
- bash: |
92+
set -xe
93+
python verify_init.py ./wheelhouse
94+
displayName: "Check for appropriate contents of _distributor_init.py"
95+
9196
- bash: |
9297
echo "##vso[task.prependpath]$CONDA/bin"
9398
sudo chown -R $USER $CONDA

verify_init.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)