Created
April 28, 2019 14:25
-
-
Save androiddrew/a4df758befa3294e87c6c187e3251e7b to your computer and use it in GitHub Desktop.
A bootstrap script for a pip-tools based Python project.
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
#!/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