Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/imh-pyth.../bin
File: virtualenvwrapper.sh
# -*- mode: shell-script -*-
[0] Fix | Delete
#
[1] Fix | Delete
# Shell functions to act as wrapper for Ian Bicking's virtualenv
[2] Fix | Delete
# (http://pypi.python.org/pypi/virtualenv)
[3] Fix | Delete
#
[4] Fix | Delete
#
[5] Fix | Delete
# Copyright Doug Hellmann, All Rights Reserved
[6] Fix | Delete
#
[7] Fix | Delete
# Permission to use, copy, modify, and distribute this software and its
[8] Fix | Delete
# documentation for any purpose and without fee is hereby granted,
[9] Fix | Delete
# provided that the above copyright notice appear in all copies and that
[10] Fix | Delete
# both that copyright notice and this permission notice appear in
[11] Fix | Delete
# supporting documentation, and that the name of Doug Hellmann not be used
[12] Fix | Delete
# in advertising or publicity pertaining to distribution of the software
[13] Fix | Delete
# without specific, written prior permission.
[14] Fix | Delete
#
[15] Fix | Delete
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
[16] Fix | Delete
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
[17] Fix | Delete
# EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
[18] Fix | Delete
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
[19] Fix | Delete
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
[20] Fix | Delete
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
[21] Fix | Delete
# PERFORMANCE OF THIS SOFTWARE.
[22] Fix | Delete
#
[23] Fix | Delete
#
[24] Fix | Delete
# Project home page: http://www.doughellmann.com/projects/virtualenvwrapper/
[25] Fix | Delete
#
[26] Fix | Delete
#
[27] Fix | Delete
# Setup:
[28] Fix | Delete
#
[29] Fix | Delete
# 1. Create a directory to hold the virtual environments.
[30] Fix | Delete
# (mkdir $HOME/.virtualenvs).
[31] Fix | Delete
# 2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
[32] Fix | Delete
# to your .bashrc.
[33] Fix | Delete
# 3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
[34] Fix | Delete
# to your .bashrc.
[35] Fix | Delete
# 4. Run: source ~/.bashrc
[36] Fix | Delete
# 5. Run: workon
[37] Fix | Delete
# 6. A list of environments, empty, is printed.
[38] Fix | Delete
# 7. Run: mkvirtualenv temp
[39] Fix | Delete
# 8. Run: workon
[40] Fix | Delete
# 9. This time, the "temp" environment is included.
[41] Fix | Delete
# 10. Run: workon temp
[42] Fix | Delete
# 11. The virtual environment is activated.
[43] Fix | Delete
#
[44] Fix | Delete
[45] Fix | Delete
# Locate the global Python where virtualenvwrapper is installed.
[46] Fix | Delete
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
[47] Fix | Delete
then
[48] Fix | Delete
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
[49] Fix | Delete
fi
[50] Fix | Delete
[51] Fix | Delete
# Set the name of the virtualenv app to use.
[52] Fix | Delete
if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ]
[53] Fix | Delete
then
[54] Fix | Delete
VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
[55] Fix | Delete
fi
[56] Fix | Delete
[57] Fix | Delete
# Set the name of the virtualenv-clone app to use.
[58] Fix | Delete
if [ "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" = "" ]
[59] Fix | Delete
then
[60] Fix | Delete
VIRTUALENVWRAPPER_VIRTUALENV_CLONE="virtualenv-clone"
[61] Fix | Delete
fi
[62] Fix | Delete
[63] Fix | Delete
# Define script folder depending on the platorm (Win32/Unix)
[64] Fix | Delete
VIRTUALENVWRAPPER_ENV_BIN_DIR="bin"
[65] Fix | Delete
if [ "$OS" = "Windows_NT" ] && ([ "$MSYSTEM" = "MINGW32" ] || [ "$MSYSTEM" = "MINGW64" ])
[66] Fix | Delete
then
[67] Fix | Delete
# Only assign this for msys, cygwin use standard Unix paths
[68] Fix | Delete
# and its own python installation
[69] Fix | Delete
VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
[70] Fix | Delete
fi
[71] Fix | Delete
[72] Fix | Delete
# Let the user override the name of the file that holds the project
[73] Fix | Delete
# directory name.
[74] Fix | Delete
if [ "$VIRTUALENVWRAPPER_PROJECT_FILENAME" = "" ]
[75] Fix | Delete
then
[76] Fix | Delete
export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project"
[77] Fix | Delete
fi
[78] Fix | Delete
[79] Fix | Delete
# Let the user tell us they never want to cd to projects
[80] Fix | Delete
# automatically.
[81] Fix | Delete
export VIRTUALENVWRAPPER_WORKON_CD=${VIRTUALENVWRAPPER_WORKON_CD:-1}
[82] Fix | Delete
[83] Fix | Delete
# Remember where we are running from.
[84] Fix | Delete
if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ]
[85] Fix | Delete
then
[86] Fix | Delete
if [ -n "$BASH" ]
[87] Fix | Delete
then
[88] Fix | Delete
export VIRTUALENVWRAPPER_SCRIPT="$BASH_SOURCE"
[89] Fix | Delete
elif [ -n "$ZSH_VERSION" ]
[90] Fix | Delete
then
[91] Fix | Delete
export VIRTUALENVWRAPPER_SCRIPT="$0"
[92] Fix | Delete
else
[93] Fix | Delete
export VIRTUALENVWRAPPER_SCRIPT="${.sh.file}"
[94] Fix | Delete
fi
[95] Fix | Delete
fi
[96] Fix | Delete
[97] Fix | Delete
# Portable shell scripting is hard, let's go shopping.
[98] Fix | Delete
#
[99] Fix | Delete
# People insist on aliasing commands like 'cd', either with a real
[100] Fix | Delete
# alias or even a shell function. Under bash and zsh, "builtin" forces
[101] Fix | Delete
# the use of a command that is part of the shell itself instead of an
[102] Fix | Delete
# alias, function, or external command, while "command" does something
[103] Fix | Delete
# similar but allows external commands. Under ksh "builtin" registers
[104] Fix | Delete
# a new command from a shared library, but "command" will pick up
[105] Fix | Delete
# existing builtin commands. We need to use a builtin for cd because
[106] Fix | Delete
# we are trying to change the state of the current shell, so we use
[107] Fix | Delete
# "builtin" for bash and zsh but "command" under ksh.
[108] Fix | Delete
function virtualenvwrapper_cd {
[109] Fix | Delete
if [ -n "$BASH" ]
[110] Fix | Delete
then
[111] Fix | Delete
builtin \cd "$@"
[112] Fix | Delete
elif [ -n "$ZSH_VERSION" ]
[113] Fix | Delete
then
[114] Fix | Delete
builtin \cd -q "$@"
[115] Fix | Delete
else
[116] Fix | Delete
command \cd "$@"
[117] Fix | Delete
fi
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
function virtualenvwrapper_expandpath {
[121] Fix | Delete
if [ "$1" = "" ]; then
[122] Fix | Delete
return 1
[123] Fix | Delete
else
[124] Fix | Delete
"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"
[125] Fix | Delete
return 0
[126] Fix | Delete
fi
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
function virtualenvwrapper_absolutepath {
[130] Fix | Delete
if [ "$1" = "" ]; then
[131] Fix | Delete
return 1
[132] Fix | Delete
else
[133] Fix | Delete
"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.abspath(\"$1\")+'\n')"
[134] Fix | Delete
return 0
[135] Fix | Delete
fi
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
function virtualenvwrapper_derive_workon_home {
[139] Fix | Delete
typeset workon_home_dir="$WORKON_HOME"
[140] Fix | Delete
[141] Fix | Delete
# Make sure there is a default value for WORKON_HOME.
[142] Fix | Delete
# You can override this setting in your .bashrc.
[143] Fix | Delete
if [ "$workon_home_dir" = "" ]
[144] Fix | Delete
then
[145] Fix | Delete
workon_home_dir="$HOME/.virtualenvs"
[146] Fix | Delete
fi
[147] Fix | Delete
[148] Fix | Delete
# If the path is relative, prefix it with $HOME
[149] Fix | Delete
# (note: for compatibility)
[150] Fix | Delete
if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \grep '^[^/~]' > /dev/null)
[151] Fix | Delete
then
[152] Fix | Delete
workon_home_dir="$HOME/$WORKON_HOME"
[153] Fix | Delete
fi
[154] Fix | Delete
[155] Fix | Delete
# Only call on Python to fix the path if it looks like the
[156] Fix | Delete
# path might contain stuff to expand.
[157] Fix | Delete
# (it might be possible to do this in shell, but I don't know a
[158] Fix | Delete
# cross-shell-safe way of doing it -wolever)
[159] Fix | Delete
if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \egrep '([\$~]|//)' >/dev/null)
[160] Fix | Delete
then
[161] Fix | Delete
# This will normalize the path by:
[162] Fix | Delete
# - Removing extra slashes (e.g., when TMPDIR ends in a slash)
[163] Fix | Delete
# - Expanding variables (e.g., $foo)
[164] Fix | Delete
# - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
[165] Fix | Delete
workon_home_dir="$(virtualenvwrapper_expandpath "$workon_home_dir")"
[166] Fix | Delete
fi
[167] Fix | Delete
[168] Fix | Delete
echo "$workon_home_dir"
[169] Fix | Delete
return 0
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
# Check if the WORKON_HOME directory exists,
[173] Fix | Delete
# create it if it does not
[174] Fix | Delete
# seperate from creating the files in it because this used to just error
[175] Fix | Delete
# and maybe other things rely on the dir existing before that happens.
[176] Fix | Delete
function virtualenvwrapper_verify_workon_home {
[177] Fix | Delete
RC=0
[178] Fix | Delete
if [ ! -d "$WORKON_HOME/" ]
[179] Fix | Delete
then
[180] Fix | Delete
if [ "$1" != "-q" ]
[181] Fix | Delete
then
[182] Fix | Delete
echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2
[183] Fix | Delete
fi
[184] Fix | Delete
mkdir -p "$WORKON_HOME"
[185] Fix | Delete
RC=$?
[186] Fix | Delete
fi
[187] Fix | Delete
return $RC
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
#HOOK_VERBOSE_OPTION="-q"
[191] Fix | Delete
[192] Fix | Delete
# Function to wrap mktemp so tests can replace it for error condition
[193] Fix | Delete
# testing.
[194] Fix | Delete
function virtualenvwrapper_mktemp {
[195] Fix | Delete
command \mktemp "$@"
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
# Expects 1 argument, the suffix for the new file.
[199] Fix | Delete
function virtualenvwrapper_tempfile {
[200] Fix | Delete
# Note: the 'X's must come last
[201] Fix | Delete
typeset suffix=${1:-hook}
[202] Fix | Delete
typeset file
[203] Fix | Delete
[204] Fix | Delete
file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)"
[205] Fix | Delete
touch "$file"
[206] Fix | Delete
if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ]
[207] Fix | Delete
then
[208] Fix | Delete
echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2
[209] Fix | Delete
return 1
[210] Fix | Delete
fi
[211] Fix | Delete
echo $file
[212] Fix | Delete
return 0
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
# Run the hooks
[216] Fix | Delete
function virtualenvwrapper_run_hook {
[217] Fix | Delete
typeset hook_script
[218] Fix | Delete
typeset result
[219] Fix | Delete
[220] Fix | Delete
hook_script="$(virtualenvwrapper_tempfile ${1}-hook)" || return 1
[221] Fix | Delete
[222] Fix | Delete
# Use a subshell to run the python interpreter with hook_loader so
[223] Fix | Delete
# we can change the working directory. This avoids having the
[224] Fix | Delete
# Python 3 interpreter decide that its "prefix" is the virtualenv
[225] Fix | Delete
# if we happen to be inside the virtualenv when we start.
[226] Fix | Delete
( \
[227] Fix | Delete
virtualenvwrapper_cd "$WORKON_HOME" &&
[228] Fix | Delete
"$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' \
[229] Fix | Delete
$HOOK_VERBOSE_OPTION --script "$hook_script" "$@" \
[230] Fix | Delete
)
[231] Fix | Delete
result=$?
[232] Fix | Delete
[233] Fix | Delete
if [ $result -eq 0 ]
[234] Fix | Delete
then
[235] Fix | Delete
if [ ! -f "$hook_script" ]
[236] Fix | Delete
then
[237] Fix | Delete
echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2
[238] Fix | Delete
command \rm -f "$hook_script"
[239] Fix | Delete
return 2
[240] Fix | Delete
fi
[241] Fix | Delete
# cat "$hook_script"
[242] Fix | Delete
source "$hook_script"
[243] Fix | Delete
elif [ "${1}" = "initialize" ]
[244] Fix | Delete
then
[245] Fix | Delete
cat - 1>&2 <<EOF
[246] Fix | Delete
virtualenvwrapper.sh: There was a problem running the initialization hooks.
[247] Fix | Delete
[248] Fix | Delete
If Python could not import the module virtualenvwrapper.hook_loader,
[249] Fix | Delete
check that virtualenvwrapper has been installed for
[250] Fix | Delete
VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is
[251] Fix | Delete
set properly.
[252] Fix | Delete
EOF
[253] Fix | Delete
fi
[254] Fix | Delete
command \rm -f "$hook_script"
[255] Fix | Delete
return $result
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
# Set up tab completion. (Adapted from Arthur Koziel's version at
[259] Fix | Delete
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
[260] Fix | Delete
function virtualenvwrapper_setup_tab_completion {
[261] Fix | Delete
if [ -n "$BASH" ] ; then
[262] Fix | Delete
_virtualenvs () {
[263] Fix | Delete
local cur="${COMP_WORDS[COMP_CWORD]}"
[264] Fix | Delete
COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
[265] Fix | Delete
}
[266] Fix | Delete
_cdvirtualenv_complete () {
[267] Fix | Delete
local cur="$2"
[268] Fix | Delete
COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
[269] Fix | Delete
}
[270] Fix | Delete
_cdsitepackages_complete () {
[271] Fix | Delete
local cur="$2"
[272] Fix | Delete
COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
[273] Fix | Delete
}
[274] Fix | Delete
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
[275] Fix | Delete
complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
[276] Fix | Delete
complete -o default -o nospace -F _virtualenvs workon
[277] Fix | Delete
complete -o default -o nospace -F _virtualenvs rmvirtualenv
[278] Fix | Delete
complete -o default -o nospace -F _virtualenvs cpvirtualenv
[279] Fix | Delete
complete -o default -o nospace -F _virtualenvs showvirtualenv
[280] Fix | Delete
elif [ -n "$ZSH_VERSION" ] ; then
[281] Fix | Delete
_virtualenvs () {
[282] Fix | Delete
reply=( $(virtualenvwrapper_show_workon_options) )
[283] Fix | Delete
}
[284] Fix | Delete
_cdvirtualenv_complete () {
[285] Fix | Delete
reply=( $(cdvirtualenv && ls -d ${1}*) )
[286] Fix | Delete
}
[287] Fix | Delete
_cdsitepackages_complete () {
[288] Fix | Delete
reply=( $(cdsitepackages && ls -d ${1}*) )
[289] Fix | Delete
}
[290] Fix | Delete
compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
[291] Fix | Delete
compctl -K _cdvirtualenv_complete cdvirtualenv
[292] Fix | Delete
compctl -K _cdsitepackages_complete cdsitepackages
[293] Fix | Delete
fi
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
# Set up virtualenvwrapper properly
[297] Fix | Delete
function virtualenvwrapper_initialize {
[298] Fix | Delete
export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
[299] Fix | Delete
[300] Fix | Delete
virtualenvwrapper_verify_workon_home -q || return 1
[301] Fix | Delete
[302] Fix | Delete
# Set the location of the hook scripts
[303] Fix | Delete
if [ "$VIRTUALENVWRAPPER_HOOK_DIR" = "" ]
[304] Fix | Delete
then
[305] Fix | Delete
export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
[306] Fix | Delete
fi
[307] Fix | Delete
[308] Fix | Delete
mkdir -p "$VIRTUALENVWRAPPER_HOOK_DIR"
[309] Fix | Delete
[310] Fix | Delete
virtualenvwrapper_run_hook "initialize"
[311] Fix | Delete
[312] Fix | Delete
virtualenvwrapper_setup_tab_completion
[313] Fix | Delete
[314] Fix | Delete
return 0
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
# Verify that the passed resource is in path and exists
[318] Fix | Delete
function virtualenvwrapper_verify_resource {
[319] Fix | Delete
typeset exe_path="$(command \which "$1" | (unset GREP_OPTIONS; command \grep -v "not found"))"
[320] Fix | Delete
if [ "$exe_path" = "" ]
[321] Fix | Delete
then
[322] Fix | Delete
echo "ERROR: virtualenvwrapper could not find $1 in your path" >&2
[323] Fix | Delete
return 1
[324] Fix | Delete
fi
[325] Fix | Delete
if [ ! -e "$exe_path" ]
[326] Fix | Delete
then
[327] Fix | Delete
echo "ERROR: Found $1 in path as \"$exe_path\" but that does not exist" >&2
[328] Fix | Delete
return 1
[329] Fix | Delete
fi
[330] Fix | Delete
return 0
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
[334] Fix | Delete
# Verify that virtualenv is installed and visible
[335] Fix | Delete
function virtualenvwrapper_verify_virtualenv {
[336] Fix | Delete
virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
[340] Fix | Delete
function virtualenvwrapper_verify_virtualenv_clone {
[341] Fix | Delete
virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV_CLONE
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
[345] Fix | Delete
# Verify that the requested environment exists
[346] Fix | Delete
function virtualenvwrapper_verify_workon_environment {
[347] Fix | Delete
typeset env_name="$1"
[348] Fix | Delete
if [ ! -d "$WORKON_HOME/$env_name" ]
[349] Fix | Delete
then
[350] Fix | Delete
echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." >&2
[351] Fix | Delete
return 1
[352] Fix | Delete
fi
[353] Fix | Delete
return 0
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
# Verify that the active environment exists
[357] Fix | Delete
function virtualenvwrapper_verify_active_environment {
[358] Fix | Delete
if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
[359] Fix | Delete
then
[360] Fix | Delete
echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2
[361] Fix | Delete
return 1
[362] Fix | Delete
fi
[363] Fix | Delete
return 0
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
# Help text for mkvirtualenv
[367] Fix | Delete
function virtualenvwrapper_mkvirtualenv_help {
[368] Fix | Delete
echo "Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name"
[369] Fix | Delete
echo
[370] Fix | Delete
echo " -a project_path"
[371] Fix | Delete
echo
[372] Fix | Delete
echo " Provide a full path to a project directory to associate with"
[373] Fix | Delete
echo " the new environment."
[374] Fix | Delete
echo
[375] Fix | Delete
echo " -i package"
[376] Fix | Delete
echo
[377] Fix | Delete
echo " Install a package after the environment is created."
[378] Fix | Delete
echo " This option may be repeated."
[379] Fix | Delete
echo
[380] Fix | Delete
echo " -r requirements_file"
[381] Fix | Delete
echo
[382] Fix | Delete
echo " Provide a pip requirements file to install a base set of packages"
[383] Fix | Delete
echo " into the new environment."
[384] Fix | Delete
echo;
[385] Fix | Delete
echo 'virtualenv help:';
[386] Fix | Delete
echo;
[387] Fix | Delete
"$VIRTUALENVWRAPPER_VIRTUALENV" $@;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
# Create a new environment, in the WORKON_HOME.
[391] Fix | Delete
#
[392] Fix | Delete
# Usage: mkvirtualenv [options] ENVNAME
[393] Fix | Delete
# (where the options are passed directly to virtualenv)
[394] Fix | Delete
#
[395] Fix | Delete
#:help:mkvirtualenv: Create a new virtualenv in $WORKON_HOME
[396] Fix | Delete
function mkvirtualenv {
[397] Fix | Delete
typeset -a in_args
[398] Fix | Delete
typeset -a out_args
[399] Fix | Delete
typeset -i i
[400] Fix | Delete
typeset tst
[401] Fix | Delete
typeset a
[402] Fix | Delete
typeset envname
[403] Fix | Delete
typeset requirements
[404] Fix | Delete
typeset packages
[405] Fix | Delete
typeset interpreter
[406] Fix | Delete
typeset project
[407] Fix | Delete
[408] Fix | Delete
in_args=( "$@" )
[409] Fix | Delete
[410] Fix | Delete
if [ -n "$ZSH_VERSION" ]
[411] Fix | Delete
then
[412] Fix | Delete
i=1
[413] Fix | Delete
tst="-le"
[414] Fix | Delete
else
[415] Fix | Delete
i=0
[416] Fix | Delete
tst="-lt"
[417] Fix | Delete
fi
[418] Fix | Delete
while [ $i $tst $# ]
[419] Fix | Delete
do
[420] Fix | Delete
a="${in_args[$i]}"
[421] Fix | Delete
# echo "arg $i : $a"
[422] Fix | Delete
case "$a" in
[423] Fix | Delete
-a)
[424] Fix | Delete
i=$(( $i + 1 ))
[425] Fix | Delete
project="${in_args[$i]}"
[426] Fix | Delete
if [ ! -d "$project" ]
[427] Fix | Delete
then
[428] Fix | Delete
echo "Cannot associate project with $project, it is not a directory" 1>&2
[429] Fix | Delete
return 1
[430] Fix | Delete
fi
[431] Fix | Delete
project="$(virtualenvwrapper_absolutepath ${project})";;
[432] Fix | Delete
-h|--help)
[433] Fix | Delete
virtualenvwrapper_mkvirtualenv_help $a;
[434] Fix | Delete
return;;
[435] Fix | Delete
-i)
[436] Fix | Delete
i=$(( $i + 1 ));
[437] Fix | Delete
packages="$packages ${in_args[$i]}";;
[438] Fix | Delete
-p|--python*)
[439] Fix | Delete
if echo "$a" | grep -q "="
[440] Fix | Delete
then
[441] Fix | Delete
interpreter="$(echo "$a" | cut -f2 -d=)"
[442] Fix | Delete
else
[443] Fix | Delete
i=$(( $i + 1 ))
[444] Fix | Delete
interpreter="${in_args[$i]}"
[445] Fix | Delete
fi;;
[446] Fix | Delete
-r)
[447] Fix | Delete
i=$(( $i + 1 ));
[448] Fix | Delete
requirements="${in_args[$i]}";
[449] Fix | Delete
requirements="$(virtualenvwrapper_expandpath "$requirements")";;
[450] Fix | Delete
*)
[451] Fix | Delete
if [ ${#out_args} -gt 0 ]
[452] Fix | Delete
then
[453] Fix | Delete
out_args=( "${out_args[@]-}" "$a" )
[454] Fix | Delete
else
[455] Fix | Delete
out_args=( "$a" )
[456] Fix | Delete
fi;;
[457] Fix | Delete
esac
[458] Fix | Delete
i=$(( $i + 1 ))
[459] Fix | Delete
done
[460] Fix | Delete
[461] Fix | Delete
if [ ! -z $interpreter ]
[462] Fix | Delete
then
[463] Fix | Delete
out_args=( "--python=$interpreter" ${out_args[@]} )
[464] Fix | Delete
fi;
[465] Fix | Delete
[466] Fix | Delete
set -- "${out_args[@]}"
[467] Fix | Delete
[468] Fix | Delete
eval "envname=\$$#"
[469] Fix | Delete
virtualenvwrapper_verify_workon_home || return 1
[470] Fix | Delete
virtualenvwrapper_verify_virtualenv || return 1
[471] Fix | Delete
(
[472] Fix | Delete
[ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT
[473] Fix | Delete
virtualenvwrapper_cd "$WORKON_HOME" &&
[474] Fix | Delete
"$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" &&
[475] Fix | Delete
[ -d "$WORKON_HOME/$envname" ] && \
[476] Fix | Delete
virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname"
[477] Fix | Delete
)
[478] Fix | Delete
typeset RC=$?
[479] Fix | Delete
[ $RC -ne 0 ] && return $RC
[480] Fix | Delete
[481] Fix | Delete
# If they passed a help option or got an error from virtualenv,
[482] Fix | Delete
# the environment won't exist. Use that to tell whether
[483] Fix | Delete
# we should switch to the environment and run the hook.
[484] Fix | Delete
[ ! -d "$WORKON_HOME/$envname" ] && return 0
[485] Fix | Delete
[486] Fix | Delete
# If they gave us a project directory, set it up now
[487] Fix | Delete
# so the activate hooks can find it.
[488] Fix | Delete
if [ ! -z "$project" ]
[489] Fix | Delete
then
[490] Fix | Delete
setvirtualenvproject "$WORKON_HOME/$envname" "$project"
[491] Fix | Delete
RC=$?
[492] Fix | Delete
[ $RC -ne 0 ] && return $RC
[493] Fix | Delete
fi
[494] Fix | Delete
[495] Fix | Delete
# Now activate the new environment
[496] Fix | Delete
workon "$envname"
[497] Fix | Delete
[498] Fix | Delete
if [ ! -z "$requirements" ]
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function