Last active
August 29, 2015 13:59
-
-
Save nhoffman/10571339 to your computer and use it in GitHub Desktop.
Create python wheels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
REQFILE="${1-requirements.txt}" | |
WHEELSTREET="${2-wheelstreet}" # base dir for wheel dirs | |
if [[ ! -f "$REQFILE" ]]; then | |
echo "Cannot find requirements file named $REQFILE" | |
echo "Usage: $(basename $0) [requirements.txt] [wheelstreet]" | |
exit 1 | |
fi | |
# get the python version | |
PYTHON=python | |
TAG=$($PYTHON -c 'import sys; print "{}.{}.{}".format(*sys.version_info[:3])') | |
PY_VER="${TAG:0:3}" | |
PY_MAJOR="${PY_VER:0:1}" | |
VENV_VERSION=1.11 | |
WHEELHOUSE="$WHEELSTREET/$TAG" # wheels for this python version | |
CACHE="$WHEELSTREET/cache" | |
VENV="$WHEELSTREET/venv" | |
mkdir -p "$CACHE" | |
rm -rf "$CACHE/*" | |
mkdir -p "$WHEELHOUSE" | |
# create virtualenv if necessary | |
if [ ! -f $VENV/bin/activate ]; then | |
# download virtualenv source if necessary | |
if [ ! -f $CACHE/virtualenv-${VENV_VERSION}/virtualenv.py ]; then | |
VENV_URL='https://pypi.python.org/packages/source/v/virtualenv' | |
(cd $CACHE && \ | |
wget -N ${VENV_URL}/virtualenv-${VENV_VERSION}.tar.gz && \ | |
tar -xf virtualenv-${VENV_VERSION}.tar.gz) | |
fi | |
$PYTHON $CACHE/virtualenv-${VENV_VERSION}/virtualenv.py $VENV | |
# $PYTHON $CACHE/virtualenv-${VENV_VERSION}/virtualenv.py --relocatable $VENV | |
else | |
echo "found existing virtualenv $VENV" | |
fi | |
source $VENV/bin/activate | |
# install wheel package to $VENV | |
pip install --download-cache $CACHE wheel | |
# put the requirements file in the wheelhouse | |
cp $REQFILE $WHEELHOUSE | |
# install and build the wheels | |
cat $REQFILE | while read pkg; do | |
# --find-links avoids rebuilding existing wheels | |
pip wheel $pkg \ | |
--allow-external argparse \ | |
--download-cache $CACHE \ | |
--use-wheel \ | |
--find-links=$WHEELHOUSE \ | |
--wheel-dir=$WHEELHOUSE | |
# install to provide dependencies for subsequent packages | |
pip install --use-wheel --find-links=$WHEELHOUSE --no-index $pkg | |
done | |
rm -r "$CACHE" | |
echo 'Created wheels:' | |
tree -F -L 2 $WHEELSTREET | |
echo 'install wheels using' | |
echo "pip install --use-wheel --find-links=$WHEELHOUSE --no-index -r $REQFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment