Created
August 10, 2011 13:53
-
-
Save gdamjan/1136847 to your computer and use it in GitHub Desktop.
A bash function to create a Python PEP-370 virtual environment, similar to virtualenv but leaner
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
# This is a shell (bash) function. you need to add it to your bashrc or bash_profile file | |
# Create a PEP-370 Python virtual environment | |
function create_env () { | |
ENV=`readlink -f $1` || return 1 | |
mkdir $ENV || return 1 | |
mkdir $ENV/bin || return 1 | |
cat <<-EOF > $ENV/bin/activate | |
# first check if other env is active | |
[ x"$PYTHONUSERBASE" != x ] && echo "PYTHONUSERBASE already active from '$PYTHONUSERBASE'. Use 'deactivate' first." && return 1 | |
# setup pep-370 | |
# alternatively ENV=$(dirname $(readlink -f $BASH_SOURCE)/..) would make the activate script stateless | |
export PYTHONUSERBASE=$ENV | |
# configure pip | |
export PIP_INSTALL_OPTION=--user | |
# setup the bash prompt | |
_OLD_PS1=\$PS1 | |
PS1="[$1]\$PS1" | |
# setup the bash path | |
_OLD_PATH=\$PATH | |
PATH=\$PYTHONUSERBASE/bin:\$PATH | |
# .. and at last allow for cleanup | |
alias deactivate='PATH=\$_OLD_PATH; PS1=\$_OLD_PS1; unset PIP_INSTALL_OPTION; unset PYTHONUSERBASE; unalias deactivate' | |
EOF | |
echo "source $ENV/bin/activate in your shell to activate this environment." | |
} | |
# end of PEP-370 creator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some documentation on http://damjan.softver.org.mk/wiki/pep-370