Created
July 12, 2014 21:31
-
-
Save miraculixx/5e863e8df7c3461c6fca to your computer and use it in GitHub Desktop.
add and remove pip install/uninstall from requirements.txt automatically
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
# add pip install/uninstall to requirements.txt automatically | |
pipr() { | |
if [ "$1" == "install" ]; then | |
pip $1 $2 | |
pip freeze | grep -i $2 >> requirements.txt | |
echo ok, added $2 as: | |
tail -n1 requirements.txt | |
fi | |
if [ "$1" == "uninstall" ]; then | |
echo y | pip $1 $2 >> .pipremoved | |
grep -i "successfully uninstalled" .pipremoved | grep -o -i $2 >> requirements.removed | |
cp requirements.txt requirements.bak | |
tail -n1 requirements.removed | xargs -I{} grep -v {} requirements.bak > requirements.txt | |
echo ok, removed: | |
tail -n1 requirements.removed | |
rm .pipremoved >/dev/nul | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
so you don't have to manually manage requirements.txt. You could use
pip freeze > requirements.txt
but this generates a lot of clutter:pip freeze
does not take into account dependencies, and so once you install more than a couple of packages, your requirements.txt becomes cluttered.pipr
only adds what you actually installed.