Skip to content

Instantly share code, notes, and snippets.

@yaythomas
Last active April 4, 2019 08:26
Show Gist options
  • Save yaythomas/2a6b408b6551d9094dc2cf45b3d46176 to your computer and use it in GitHub Desktop.
Save yaythomas/2a6b408b6551d9094dc2cf45b3d46176 to your computer and use it in GitHub Desktop.
upgrade global virtualenv when require-virtualenv or PIP_REQUIRE_VIRTUALENV true

if you do all your python in virtualenvs, and you probably should be, the one package that sits in global is virtualenv.

when you upgrade your python installation, those virtualenvs do not upgrade themselves. you have to go and re-create your virtualenv when you upgrade python. this is annoying. this is even more annoying when you have pip.conf set with

[install]
require-virtualenv = true

[uninstall]
require-virtualenv = true

because obviously you'll get something like "Could not find an activated virtualenv (required)." if you try to run a bare --upgrade.

this script

  1. upgrades global virtualenv, bypassing the require-virtualenv flag just for the purposes of this install
  2. create a virtualenv in ~/envs/python, which will be the latest python on your system
  3. create a virtualenv in ~/envs/pypyr, containing pypyr + plugins.
#!/usr/bin/env bash
# DONT run me from a venv
# the idea is to upgrade the one global venv package
# and then to recreate the bare minimun venvs for latest python and
# latest pypyr. other more complex venvs create from pypyr create dev env
# pipelines.
# base python env
IN_VENV=$(python -c 'import sys; print ("1" if hasattr(sys, "real_prefix") else "0")')
# [[ ${IN_VENV} -eq 1 ]] || { echo >&2 "don't run me from a venv. deactivate first."; exit 1; }
if [ ${IN_VENV} -eq 1 ]
then
echo >&2 "don't run me from a venv. deactivate first.";
exit 1;
else
echo not in a venv, thats good. recreating venvs.
fi
env PIP_REQUIRE_VIRTUALENV='0' pip install --upgrade pip
rm -rf ~/envs/python
python3 -m venv ~/envs/python
. ~/envs/python/bin/activate
pip install --upgrade pip setuptools wheel
# pypyr env
rm -rf ~/envs/pypyr
python3 -m venv ~/envs/pypyr
. ~/envs/pypyr/bin/activate
pip install --upgrade pip setuptools wheel pypyr pypyrslack pypyraws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment