Last active
November 9, 2019 19:49
-
-
Save nathairtras/7b2df168d9a919b4e644b1d7da0aa05d to your computer and use it in GitHub Desktop.
Script for fixing broken Brew VirtualEnvWrapper environments
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 | |
# @@TODO: Script assumes Python3. If you are wanting to fix a Python2 Virtual Environment, | |
# consider adding a command line argument to specify which python to use and adjust the `mkvirtualenv` line. | |
# Reminder: Python2 is EOL Jan1 2020, so script assumes you wouldn't want to do that... | |
# Ensure virtualenv script exists | |
if [ -z $VIRTUALENVWRAPPER_SCRIPT ] | |
then | |
echo "VirtualEnvWrapper Script Environment Variable Not Found. Please run `pip3 install virtualenvwrapper` to continue." | |
exit 1 | |
fi | |
# Ensure WORKON_HOME set | |
if [ -z $WORKON_HOME ] | |
then | |
echo "$WORKON_HOME is not set. Please ensure this is set in your environment before continuing to ensure correct execution." | |
exit 1 | |
fi | |
# Verify first argument is a valid virtualenv | |
VENV_DIR="$WORKON_HOME/$1" | |
if [ -z "$1" ] | |
then | |
echo "No Virtual Environment Supplied" | |
exit 1 | |
elif [ -d $VENV_DIR ] | |
then | |
: | |
else | |
echo "Please Supply Valid Virtual Environment Name" | |
exit 1 | |
fi | |
# Run the cleanup job | |
# @@TODO: This assumes Python3 | |
source $VIRTUALENVWRAPPER_SCRIPT | |
cd $VENV_DIR | |
find . -type l -delete | |
mkvirtualenv $1 --python=`which python3` | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment