Skip to content

Instantly share code, notes, and snippets.

@tacaswell
Last active September 21, 2018 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tacaswell/1d36a5ecc372f65e9f46 to your computer and use it in GitHub Desktop.
Save tacaswell/1d36a5ecc372f65e9f46 to your computer and use it in GitHub Desktop.
patch over conda vs venvs idea of activate
#! /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.
@onlyjus
Copy link

onlyjus commented Oct 15, 2014

Could this patch be done in pure Python so that Python apps (Spyder) using Qt could fix this when called?

@tacaswell
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment