-
-
Save tacaswell/1d36a5ecc372f65e9f46 to your computer and use it in GitHub Desktop.
patch over conda vs venvs idea of activate
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
#! /bin/bash | |
if [ -a $1/bin/conda ]; then | |
# we are in a conda env | |
# save old QT_PLUGIN_PATH | |
OLD_QT=$QT_PLUGIN_PATH | |
# save old PS1 | |
OLD_PS=$PS1 | |
# source activate script | |
source $1/bin/activate $1 | |
# set PS1 to behave sanely | |
PS1="(`basename \"$1\"`)$OLD_PS" | |
# if qt.conf does not exist, make it | |
if [ ! -a $1/bin/qt.conf ]; then | |
echo "[Paths] | |
Plguins = '.' | |
" > $1/bin/qt.conf | |
fi | |
# also blow-away system related qt-plugin paths | |
export QT_PLUGIN_PATH='' | |
# create a function so deactivate works like it does for | |
# venvs | |
function deactivate() { | |
# source conda's deactivate | |
source deactivate | |
# delete self | |
unset deactivate | |
# reset the PS1 (we could probably trust the conda | |
# deactivate to do this, but just to be safe) | |
PS1=$OLD_PS | |
# re-set the QT_PLUGIN_PATH | |
export QT_PLUGIN_PATH=$OLD_QT | |
# clean up after self | |
unset OLD_PS | |
unset OLD_QT | |
} | |
else | |
# we are using a venv | |
# all we need to do is source the activate script | |
source $1/bin/activate | |
fi | |
# calling | |
# $ source wo /path/to/venv | |
# will 'do the right thing' in both cases | |
# as will | |
# $ deactivate | |
# I have the following in my .bashrc | |
# alias activate='. wo' | |
# so that | |
# $ activate /path/to/venv | |
# works. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@onlyjus I just saw this now. This isn't really a patch, but a shell script I use to activate venvs. Doing it this way is better as it is completely transparent to any applications run from with in the environment.