Skip to content

Commit

Permalink
Build packages and perform package sanity tests. Fixes #136
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Mar 12, 2018
1 parent cc6e7c7 commit 1aabc0d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
22 changes: 18 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ python:
- 3.5
- 3.6
env:
- DJANGO=1.11
# note: latest versions first b/c the top-most is included in new
# build stages if not specified
- DJANGO=2.0
- DJANGO=1.11
stages:
- django_not_installed
- django_is_installed
- test
- build_and_package_sanity
matrix:
exclude:
# Python/Django combinations that aren't officially supported
Expand All @@ -21,6 +24,7 @@ matrix:
- { stage: test, python: 3.6, env: TOXENV=flake8 }
- { stage: test, python: 3.6, env: TOXENV=pylint }
- { stage: test, python: 3.6, env: TOXENV=readme }
- { stage: build_and_package_sanity, python: 3.6, env: SANITY_CHECK=1 }
allow_failures:
- env: TOXENV=flake8
- env: TOXENV=pylint
Expand All @@ -29,11 +33,21 @@ matrix:
install:
- pip install tox-travis
script:
- tox
- |
if [ -z "$SANITY_CHECK" ]; then
tox
else
./scripts/build.sh
fi
after_success:
- pip install coveralls
- coveralls
- |
if [ -z "$SANITY_CHECK" ]; then
pip install coveralls
coveralls
fi
notifications:
email:
on_failure: change
Expand Down
81 changes: 81 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Build packages for distribution on PyPI
# and execute some sanity scripts on them
#
# note: must be executed from the root directory of the project

# first clean up the local environment
echo "..... Clean up first"
find . -type f -name '*.pyc' -delete
find . -type d -name __pycache__ -delete
find . -type d -name '*.egg-info' | xargs rm -rf
rm -rf build/ .cache/ dist/ .eggs/ .tox/

# then build the packages
echo "..... Building PyPI packages"
set -e
python setup.py sdist >/dev/null
python setup.py bdist_wheel >/dev/null
set +e

# then run some sanity tests
echo "..... Searching for .pyc files inside the built packages"
matched_files=`tar -tvf dist/*.tar.gz | grep -c "\.pyc"`
if [ "$matched_files" -gt "0" ]; then
echo "ERROR: .pyc files found in .tar.gz package"
exit 1
fi
matched_files=`unzip -t dist/*.whl | grep -c "\.pyc"`
if [ "$matched_files" -gt "0" ]; then
echo "ERROR: .pyc files found in wheel package"
exit 1
fi

echo "..... Trying to verify that all source files are present"
# remove pylint_django/*.egg-info/ generated during build
find . -type d -name '*.egg-info' | xargs rm -rf

source_files=`find ./pylint_django/ -type f | sed 's|./||'`

# verify for .tar.gz package
package_files=`tar -tvf dist/*.tar.gz`
for src_file in $source_files; do
echo "$package_files" | grep $src_file >/dev/null
if [ "$?" -ne 0 ]; then
echo "ERROR: $src_file not found inside tar.gz package"
exit 1
fi
done

# verify for wheel package
package_files=`unzip -t dist/*.whl`
for src_file in $source_files; do
echo "$package_files" | grep $src_file >/dev/null
if [ "$?" -ne 0 ]; then
echo "ERROR: $src_file not found inside wheel package"
exit 1
fi
done

# exit on error from now on
set -e

echo "..... Trying to install the new tarball inside a virtualenv"
# note: installs with the optional dependency to verify this is still working
virtualenv .venv/test-tarball
source .venv/test-tarball/bin/activate
pip install --no-binary :all: -f dist/ pylint_django[with_django]
pip freeze | grep Django
deactivate
rm -rf .venv/

echo "..... Trying to install the new wheel inside a virtualenv"
virtualenv .venv/test-wheel
source .venv/test-wheel/bin/activate
pip install pylint-plugin-utils # because it does not provide a wheel package
pip install --only-binary :all: -f dist/ pylint_django
deactivate
rm -rf .venv/

echo "..... PASS"

0 comments on commit 1aabc0d

Please sign in to comment.