Skip to content

Instantly share code, notes, and snippets.

@jlinoff
Created March 22, 2017 00:37
Show Gist options
  • Save jlinoff/653dae6efe807817d8ac3ff9a6afd34b to your computer and use it in GitHub Desktop.
Save jlinoff/653dae6efe807817d8ac3ff9a6afd34b to your computer and use it in GitHub Desktop.
Python wheel example.
#!/bin/bash
#
# This script demonstrates how to create wheels for distributing the
# packages in a virtualenv.
#
# It first creates a virtualenv named "venv" and populates it with
# several packages. After that it creates wheels of all of the
# packages in the virtualenv for distribution in the wheel
# subdirectory.
#
# It then creates a second virtualenv named "venv1" which populates
# itself with the packages using the wheels only.
#
# Note that this assumes that the python versions on the producer and
# consumers systems is the same. For this case it would probably be
# easier to install the virtualenv in a known place like
# /opt/myapp/venv, then tar or zip it up and distribute it as an
# archive that is restored to a fixed place. If you did not want to
# put it in a fixed place, you could always use the virtual
# --relocatable option.
#
# License: MIT Open Source
# Copyright (c) 2017 by Joe Linoff
#
# ================================================================
# Functions
# ================================================================
function run() {
local Cmd="$*"
local LineNum=${BASH_LINENO[0]}
echo
echo "INFO:${LineNum}: cmd.run=$Cmd"
eval "$Cmd"
local st=$?
echo "INFO:${LineNum}: cmd.status=$st"
if (( st )) ; then
echo "ERROR:${LineNum}: command failed"
exit 1
fi
}
# ================================================================
# Main
# ================================================================
deactivate
run rm -rf venv venv1 wheel *~
# Create the wheels.
run virtualenv venv
run source venv/bin/activate
run which python
run which pip
run pip help
run pip install cryptography
run pip install numpy
run pip install virtualenv
run mkdir wheel
run pip freeze '>' wheel/pkgs.txt
run cd wheel
run pip wheel -r pkgs.txt
run cd ..
run deactivate
# Deploy them.
run virtualenv venv1
run source venv1/bin/activate
run which python
run which pip
run pip install --no-index --find-links wheel wheel/cryptography*.whl
run pip install --no-index --find-links wheel wheel/numpy*.whl
run pip install --no-index --find-links wheel wheel/virtualenv*.whl
run python -c "'import cryptography ; cryptography.__version__'"
run deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment