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

Commit

Permalink
Merge pull request #151 from tylerjereddy/treddy_verify_init
Browse files Browse the repository at this point in the history
MAINT, CI: check _distributor_init.py contents
  • Loading branch information
tylerjereddy committed Nov 28, 2021
2 parents f1d2caa + cc17ad7 commit 14f94fe
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ build_script:
$cwd = Get-Location
ls $cwd
rm -Force $cwd/scipy/scipy/_distributor_init.py
mv $cwd/_distributor_init.py $cwd/scipy/scipy/
cp $cwd/_distributor_init.py $cwd/scipy/scipy/
cd scipy
# Append license text relevant for the built wheel
- type ..\LICENSE_win32.txt >> LICENSE.txt
Expand Down Expand Up @@ -198,6 +198,10 @@ test_script:
- python ..\run_scipy_tests.py %TEST_MODE% -- -n6 --junitxml=%cd%\junit-results.xml -rfEX

after_test:
- cd ..
- ls scipy\dist
- python verify_init.py scipy\dist
- cd tmp_test
# Upload test results to Appveyor
- ps: |
If (Test-Path .\junit-results.xml) {
Expand Down
5 changes: 5 additions & 0 deletions azure-posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ jobs:
displayName: "Rename MacOS arm64 wheels for version 12.0 minimum"
condition: eq(variables['PLAT'], 'arm64')
- bash: |
set -xe
python verify_init.py ./wheelhouse
displayName: "Check for appropriate contents of _distributor_init.py"
- bash: |
echo "##vso[task.prependpath]$CONDA/bin"
sudo chown -R $USER $CONDA
Expand Down
2 changes: 1 addition & 1 deletion patch_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ if [ -z "$IS_OSX" ]; then
cat LICENSE_linux.txt >> $repo_dir/LICENSE.txt
else
cat LICENSE_osx.txt >> $repo_dir/LICENSE.txt
cp _distributor_init.py scipy/_distributor_init.py
cp _distributor_init.py scipy/scipy/_distributor_init.py
fi
40 changes: 40 additions & 0 deletions verify_init.py
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)

0 comments on commit 14f94fe

Please sign in to comment.