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 9, 2018
1 parent 2dbcb18 commit fcffa89
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
11 changes: 9 additions & 2 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 }
allow_failures:
- env: TOXENV=flake8
- env: TOXENV=pylint
Expand All @@ -29,7 +33,10 @@ matrix:
install:
- pip install tox-travis
script:
- tox
- |
export
set
tox
after_success:
- pip install coveralls
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 fcffa89

Please sign in to comment.