Last active
October 21, 2016 15:38
-
-
Save eduardocardoso/04835256f79e42e84b57c8932fbac03c to your computer and use it in GitHub Desktop.
Shell script to install pip packages and add them to requirements.txt
This file contains 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
pipi() { | |
REQ_FILE=requirements.txt | |
TMP_FILE=/tmp/tmp_req.txt | |
pip install "$@" | |
if [ $? -eq 0 ] && [ -f "${REQ_FILE}" ] | |
then | |
FREEZE="$(pip freeze)" | |
for arg in "$@" | |
do | |
if [[ $arg != -* ]]; then | |
# sed -i "/^$arg[=<>]/dI" $REQ_FILE # Should work on newer sed versions | |
grep -vi "$arg[=<>]" $REQ_FILE > $TMP_FILE | |
mv $TMP_FILE $REQ_FILE | |
echo "$FREEZE" | grep -i "^$arg[=<>]" >> $REQ_FILE | |
fi | |
done | |
fi | |
} |
This file contains 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
pipi() { | |
REQ_FILE=requirements.txt | |
pip install "$@" | |
if [ $? -eq 0 ] && [ -f "${REQ_FILE}" ] | |
then | |
FREEZE="$(pip freeze)" | |
for arg in "$@" | |
do | |
if [[ $arg != -* ]]; then | |
SED_ARG=$(cat $REQ_FILE | grep -i "^$arg[=<>]") | |
TEMP=$(sed -e "/^${SED_ARG}$/d" $REQ_FILE) | |
echo "$TEMP" > $REQ_FILE | |
echo "$FREEZE" | grep -i "^$arg[=<>]" >> $REQ_FILE | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment