Last active
April 11, 2017 18:57
-
-
Save wolever/a2fb38b18ff472fa6ed3822c1e5c84f8 to your computer and use it in GitHub Desktop.
A totally untested script for upgrading a virtualenv
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
#!/bin/bash | |
set -eu | |
if [[ -z "${1-}" ]]; then | |
echo "USAGE: $0 VIRTUAL_ENV_DIR" | |
exit 1 | |
fi | |
venv="$1" | |
. "$venv/bin/activate" | |
cleanup() { | |
[ -e "${tmp_reqs-}" ] && rm "${tmp_reqs}" | |
[ ! -e "$venv" ] && mv "$venv.old" "$venv" | |
} | |
trap cleanup EXIT | |
tmp_reqs="$(mktemp /tmp/requirements.txt.XXXXX)" | |
pip freeze > "$tmp_reqs" | |
deactivate | |
mv "$venv" "$venv.old" | |
virtualenv "$venv" | |
. "$venv/bin/activate" | |
pip install -r "$tmp_reqs" | |
echo "Done." | |
echo "Remove the old virtualenv once you've confirmed that the new one works:" | |
echo " $venv.old" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment