Skip to content

Instantly share code, notes, and snippets.

@androiddrew
Created April 28, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save androiddrew/a4df758befa3294e87c6c187e3251e7b to your computer and use it in GitHub Desktop.
Save androiddrew/a4df758befa3294e87c6c187e3251e7b to your computer and use it in GitHub Desktop.
A bootstrap script for a pip-tools based Python project.
#!/usr/bin/env bash
# setting -e to exit immediately on a command failure.
# setting -o pipefail sets the exit code of a pipeline to that of the rightmost command to exit with a non-zero status, or to zero if all commands of the pipeline exit successfully.
set -eo pipefail
# Most likely you will only need to change the path variables per your project structure.
DEV_REQ_PATH=./
REQ_PATH=./services/cms/
IN_FILE_EXT=".in"
OUT_FILE_EXT=".txt"
DEV_FILE_NAME="dev_requirements"
REQ_FILE_NAME="requirements"
IN_DEV_FINAL=$DEV_REQ_PATH$DEV_FILE_NAME$IN_FILE_EXT
IN_REQ_FINAL=$REQ_PATH$REQ_FILE_NAME$IN_FILE_EXT
OUT_DEV_FINAL=$DEV_REQ_PATH$DEV_FILE_NAME$OUT_FILE_EXT
OUT_REQ_FINAL=$REQ_PATH$REQ_FILE_NAME$OUT_FILE_EXT
if [ -z "$VIRTUAL_ENV" ]; then
echo "WARNING: you are not in a virtualenv"
exit 1
fi
# Check to see if pip-tools is installed if not install it.
if [ ! "pip show pip-tools" ]; then
echo "INFO: pip-tools not found. Installing now."
pip install -U pip pip-tools
echo "INFO: pip-tools installed"
fi
# Compile requirements if file does not already exist
if [ ! -f "$OUT_REQ_FINAL" ]; then
echo "INFO: pip-tools compiling $OUT_REQ_FINAL"
pip-compile $IN_REQ_FINAL -o $OUT_REQ_FINAL
fi
if [ ! -f "$OUT_DEV_FINAL" ]; then
echo "INFO: pip-tools compiling $OUT_DEV_FINAL"
pip-compile $IN_DEV_FINAL -o $OUT_DEV_FINAL
fi
# Sync Virtualenv
echo "INFO: pip-tools syncing virtualenv"
pip-sync $OUT_REQ_FINAL $OUT_DEV_FINAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment