Skip to content

Instantly share code, notes, and snippets.

@aaronsaderholm
Last active July 17, 2017 20:49
Show Gist options
  • Save aaronsaderholm/c1dce0bb7d9a85d1d16d1af4f424ef4e to your computer and use it in GitHub Desktop.
Save aaronsaderholm/c1dce0bb7d9a85d1d16d1af4f424ef4e to your computer and use it in GitHub Desktop.
Setup python virtualenv and run pip install when requirements.txt changes
#!/bin/bash
# Creates venv if it dosen't exist and installs requirements.txt.
# Saves a checksum of requirements.txt, checks against that.
# Reruns pip install if checksum changes on subsequent runs.
# TODO:
# - Make python/ folder prefix customizable.
# - Use git version instead of crc32.
# Aaron Saderholm 7/16/17
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f "venv/bin/activate" ]; then
virtualenv venv
else
echo "virtualenv exists; skipping creation."
fi
source venv/bin/activate
REQPATH=$DIR/requirements.txt
REQCRC_FILE="$DIR/venv/req_checksum_$(crc32 "$REQPATH")"
# I'm assuming there's not going to be a file matching a checksum name in
# the root venv directory but you might not want to make that assumption.
if [ ! -f "$REQCRC_FILE" ]; then
pip install -r $DIR/requirements.txt
rm -f $DIR/venv/req_checksum*
touch $REQCRC_FILE
else
echo "found checksum matching requirements.txt, skipping install."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment