-
-
Save alexsavio/7580457 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# This hook is run after a new virtualenv is activated. | |
# ~/.virtualenvs/postmkvirtualenv | |
# determine if virtualenv is activated | |
python -c 'import sys; print(sys.real_prefix)' 2>/dev/null && INVENV=1 || INVENV=0 | |
if [ ! $INVENV == 1 ]; then | |
echo "You must activate a virtualenv for this to work." | |
exit -1 | |
fi | |
function find_real_lib { | |
syspy=$1 | |
libname=$2 | |
syspath=$($syspy -c "import sys; print(' '.join(sys.path).strip())") | |
for libdir in $syspath; do | |
if [ -e $libdir/$libname ]; then | |
eval "$3=$libdir/$libname" | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
libs=( PyQt5 sip.so vtk cairo OpenGL) | |
#libs=( vtk cairo ) | |
python_version=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))") | |
pythons=( $(which -a $python_version) ) | |
length=${#pythons[@]} | |
last_idx=$((length-1)) | |
syspy=${pythons[${last_idx}]} | |
echo "Looking for installed modules in ${syspy}" | |
get_python_lib_cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib())" | |
lib_virtualenv_path=$(python -c "$get_python_lib_cmd") | |
for lib in ${libs[@]} | |
do | |
libsyspath="" | |
find_real_lib $syspy $lib libsyspath | |
dest=$lib_virtualenv_path/$lib | |
if [ -e $dest ]; then | |
echo "Module $lib already linked in $dest." | |
else | |
if [ "$libsyspath" != "" ]; then | |
echo "Linking $lib" | |
ln -s $libsyspath $dest | |
else | |
echo "Could not find system's $lib" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment