Skip to content

Instantly share code, notes, and snippets.

@wolever
Last active April 11, 2017 18:57
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 wolever/a2fb38b18ff472fa6ed3822c1e5c84f8 to your computer and use it in GitHub Desktop.
Save wolever/a2fb38b18ff472fa6ed3822c1e5c84f8 to your computer and use it in GitHub Desktop.
A totally untested script for upgrading a virtualenv
#!/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