Skip to content

Instantly share code, notes, and snippets.

@Midnighter
Forked from jlesquembre/postmkvirtualenv
Last active January 25, 2017 07:26
Show Gist options
  • Save Midnighter/5115f13d34f0b38197df to your computer and use it in GitHub Desktop.
Save Midnighter/5115f13d34f0b38197df to your computer and use it in GitHub Desktop.
link PyQt components into new virtualenv after creation (`postmkvirtualenv`)
#!/usr/bin/env bash
# This hook is run after a new virtualenv is activated.
#set -e # abort after any errors
#set -u # exit after accessing an undefined variable
libs=(PyQt4 sip.so sipconfig.py)
python_version=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
var=( $(which -a ${python_version}) )
if [ ${#var[@]} -lt 2 ]; then
echo "could not find system install of ${python_version}: unable to link PyQt components" >&2
else
get_python_lib_cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
lib_virtualenv_path=$(${var[0]} -c "${get_python_lib_cmd}")
lib_system_path=$(${var[-1]} -c "${get_python_lib_cmd}")
for lib in ${libs[@]}
do
if [ ! -e "${lib_virtualenv_path}/${lib}" ]; then
ln -s "${lib_system_path}/${lib}" "${lib_virtualenv_path}/${lib}"
fi
done
fi
@Midnighter
Copy link
Author

I avoid set -e and set -u myself here because I work in tmux and exiting the script will close my window.

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