|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Build packages for distribution on PyPI |
| 4 | +# and execute some sanity scripts on them |
| 5 | +# |
| 6 | +# note: must be executed from the root directory of the project |
| 7 | + |
| 8 | +# first clean up the local environment |
| 9 | +echo "..... Clean up first" |
| 10 | +find . -type f -name '*.pyc' -delete |
| 11 | +find . -type d -name __pycache__ -delete |
| 12 | +find . -type d -name '*.egg-info' | xargs rm -rf |
| 13 | +rm -rf build/ .cache/ dist/ .eggs/ .tox/ |
| 14 | + |
| 15 | +# then build the packages |
| 16 | +echo "..... Building PyPI packages" |
| 17 | +set -e |
| 18 | +python setup.py sdist >/dev/null |
| 19 | +python setup.py bdist_wheel >/dev/null |
| 20 | +set +e |
| 21 | + |
| 22 | +# then run some sanity tests |
| 23 | +echo "..... Searching for .pyc files inside the built packages" |
| 24 | +matched_files=`tar -tvf dist/*.tar.gz | grep -c "\.pyc"` |
| 25 | +if [ "$matched_files" -gt "0" ]; then |
| 26 | + echo "ERROR: .pyc files found in .tar.gz package" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | +matched_files=`unzip -t dist/*.whl | grep -c "\.pyc"` |
| 30 | +if [ "$matched_files" -gt "0" ]; then |
| 31 | + echo "ERROR: .pyc files found in wheel package" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "..... Trying to verify that all source files are present" |
| 36 | +# remove pylint_django/*.egg-info/ generated during build |
| 37 | +find . -type d -name '*.egg-info' | xargs rm -rf |
| 38 | + |
| 39 | +source_files=`find ./pylint_django/ -type f | sed 's|./||'` |
| 40 | + |
| 41 | +# verify for .tar.gz package |
| 42 | +package_files=`tar -tvf dist/*.tar.gz` |
| 43 | +for src_file in $source_files; do |
| 44 | + echo "$package_files" | grep $src_file >/dev/null |
| 45 | + if [ "$?" -ne 0 ]; then |
| 46 | + echo "ERROR: $src_file not found inside tar.gz package" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +done |
| 50 | + |
| 51 | +# verify for wheel package |
| 52 | +package_files=`unzip -t dist/*.whl` |
| 53 | +for src_file in $source_files; do |
| 54 | + echo "$package_files" | grep $src_file >/dev/null |
| 55 | + if [ "$?" -ne 0 ]; then |
| 56 | + echo "ERROR: $src_file not found inside wheel package" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +done |
| 60 | + |
| 61 | +# exit on error from now on |
| 62 | +set -e |
| 63 | + |
| 64 | +echo "..... Trying to install the new tarball inside a virtualenv" |
| 65 | +# note: installs with the optional dependency to verify this is still working |
| 66 | +virtualenv .venv/test-tarball |
| 67 | +source .venv/test-tarball/bin/activate |
| 68 | +pip install --no-binary :all: -f dist/ pylint_django[with_django] |
| 69 | +pip freeze | grep Django |
| 70 | +deactivate |
| 71 | +rm -rf .venv/ |
| 72 | + |
| 73 | +echo "..... Trying to install the new wheel inside a virtualenv" |
| 74 | +virtualenv .venv/test-wheel |
| 75 | +source .venv/test-wheel/bin/activate |
| 76 | +pip install pylint-plugin-utils # because it does not provide a wheel package |
| 77 | +pip install --only-binary :all: -f dist/ pylint_django |
| 78 | +deactivate |
| 79 | +rm -rf .venv/ |
| 80 | + |
| 81 | +echo "..... PASS" |
0 commit comments