Skip to content

Instantly share code, notes, and snippets.

@andrlik
Last active April 12, 2018 17:14
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 andrlik/ab163aa30327e8a046c2eed447e42787 to your computer and use it in GitHub Desktop.
Save andrlik/ab163aa30327e8a046c2eed447e42787 to your computer and use it in GitHub Desktop.
Sync pipenv lockfile to pip-compatible requirements files.
#! /usr/bin/env bash
PRODUCTION_FILE='requirements.txt'
DEV_FILE='test_requirements.txt'
usage="$(basename "$0") [-h/--help] [-p FILENAME] [-d FILENAME] -- Program to sync pipenv lockfile to pip-compatible requirements.
where:
-h/--help Show this help text
-p FILENAME Specify what file should be used for production packages (default: requirements.txt)
-d FILENAME Specify what file should be used for development packages (default: test_requirements.txt)
-l Lock/pin the versions (note, VCS packages will always be pinned.)
"
lock=false
while [ ! $# -eq 0 ]
do
shift_twice=true
case "$1" in
--help | -h)
echo "$usage"
exit
shift_twice=false
;;
-p )
PRODUCTION_FILE="$2"
;;
-d )
DEV_FILE="$2"
;;
-l )
lock=true
shift_twice=false
;;
* )
echo "You have specified an invalid option."
echo "$usage"
exit 1
;;
esac
if [ "$shift_twice" = true ];then
shift
shift
else
shift
fi
done
echo "Starting sync of Pipenv to pip-compatible requirements..."
echo "-------------"
if [ "$PRODUCTION_FILE" != "requirements.txt" ]; then
echo "Using production file of ${PRODUCTION_FILE}."
fi
echo "Syncing production requirement packages..."
if [ "$lock" = true ];then
echo "Pinning requirements..."
pipenv lock --requirements | grep -v "#" | cut -d' ' -f1 > $PRODUCTION_FILE
else
pipenv lock --requirements | grep -v "#" | sed 's/==.*//' > $PRODUCTION_FILE
fi
echo "Syncing production VCS packages..."
pipenv lock --requirements | grep "#" | sed 's/# //' >> $PRODUCTION_FILE
echo "Finished production packages!"
echo "--------------"
if [ "$DEV_FILE" != "test_requirements.txt" ]; then
echo "Using development file of ${DEV_FILE}."
fi
echo "Syncing dev requirement packages..."
if [ "$lock" = true ];then
echo "Pinning requirements..."
pipenv lock --dev --requirements | grep -v "#" | cut -d' ' -f1 > $DEV_FILE
else
pipenv lock --dev --requirements | grep -v "#" | sed 's/==.*//' > $DEV_FILE
fi
echo "Syncing dev VCS packages..."
pipenv lock --dev --requirements | grep "#" | sed 's/# //' >> $DEV_FILE
echo "Finished dev packages!"
echo "--------------"
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment