56
56
VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
59
# Define script folder depending on the platorm (Win32/Unix)
60
VIRTUALENVWRAPPER_ENV_BIN_DIR="bin"
61
if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
63
# Only assign this for msys, cygwin use standard Unix paths
64
# and its own python installation
65
VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
59
68
virtualenvwrapper_derive_workon_home() {
60
69
typeset workon_home_dir="$WORKON_HOME"
133
142
echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
145
if [ -z "$VIRTUALENVWRAPPER_LOG_DIR" ]
147
echo "ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
136
150
"$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
166
# Set up tab completion. (Adapted from Arthur Koziel's version at
167
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
168
virtualenvwrapper_setup_tab_completion () {
169
if [ -n "$BASH" ] ; then
171
local cur="${COMP_WORDS[COMP_CWORD]}"
172
COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
174
_cdvirtualenv_complete () {
176
COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
178
_cdsitepackages_complete () {
180
COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
182
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
183
complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
184
complete -o default -o nospace -F _virtualenvs workon
185
complete -o default -o nospace -F _virtualenvs rmvirtualenv
186
complete -o default -o nospace -F _virtualenvs cpvirtualenv
187
complete -o default -o nospace -F _virtualenvs showvirtualenv
188
elif [ -n "$ZSH_VERSION" ] ; then
190
reply=( $(virtualenvwrapper_show_workon_options) )
192
_cdvirtualenv_complete () {
193
reply=( $(cdvirtualenv && ls -d ${1}*) )
195
_cdsitepackages_complete () {
196
reply=( $(cdsitepackages && ls -d ${1}*) )
198
compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
199
compctl -K _cdvirtualenv_complete cdvirtualenv
200
compctl -K _cdsitepackages_complete cdsitepackages
152
204
# Set up virtualenvwrapper properly
153
205
virtualenvwrapper_initialize () {
154
206
export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
173
225
echo "virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
229
virtualenvwrapper_setup_tab_completion
178
234
# Verify that virtualenv is installed and visible
179
235
virtualenvwrapper_verify_virtualenv () {
180
236
typeset venv=$(\which "$VIRTUALENVWRAPPER_VIRTUALENV" | (unset GREP_OPTIONS; \grep -v "not found"))
221
277
eval "envname=\$$#"
222
278
virtualenvwrapper_verify_workon_home || return 1
223
279
virtualenvwrapper_verify_virtualenv || return 1
224
(cd "$WORKON_HOME" &&
281
[ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT
282
\cd "$WORKON_HOME" &&
225
283
"$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" &&
226
284
[ -d "$WORKON_HOME/$envname" ] && \
227
285
virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname"
230
288
[ $RC -ne 0 ] && return $RC
258
316
# Move out of the current directory to one known to be
259
317
# safe, in case we are inside the environment somewhere.
260
318
typeset prior_dir="$(pwd)"
263
321
virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
264
322
\rm -rf "$env_dir"
277
335
# NOTE: DO NOT use ls here because colorized versions spew control characters
278
336
# into the output list.
279
337
# echo seems a little faster than find, even with -depth 3.
280
(cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed 's|/bin/activate||' | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
282
# (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
338
(\cd "$WORKON_HOME"; for f in */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate; do echo $f; done) 2>/dev/null | \sed 's|^\./||' | \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate||" | \sort | (unset GREP_OPTIONS; \egrep -v '^\*$')
340
# (\cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
285
343
_lsvirtualenv_usage () {
294
352
# Usage: lsvirtualenv [-l]
295
353
lsvirtualenv () {
297
args=($(getopt blh "$@"))
303
355
typeset long_mode=true
308
-b) long_mode=false;;
309
-h) _lsvirtualenv_usage;
356
if command -v "getopts" &> /dev/null
358
# Use getopts when possible
360
while getopts ":blh" opt "$@"
365
h) _lsvirtualenv_usage;
367
?) echo "Invalid option: -$OPTARG" >&2;
373
# fallback on getopt for other shell
375
args=($(getopt blh "$@"))
385
-b) long_mode=false;;
386
-h) _lsvirtualenv_usage;
357
435
virtualenvwrapper_verify_workon_home || return 1
358
436
virtualenvwrapper_verify_workon_environment $env_name || return 1
360
activate="$WORKON_HOME/$env_name/bin/activate"
438
activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
361
439
if [ ! -f "$activate" ]
363
441
echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2
390
468
# any settings made by the local postactivate first.
391
469
virtualenvwrapper_run_hook "pre_deactivate"
393
env_postdeactivate_hook="$VIRTUAL_ENV/bin/postdeactivate"
471
env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
394
472
old_env=$(basename "$VIRTUAL_ENV")
396
474
# Call the original function.
417
# Set up tab completion. (Adapted from Arthur Koziel's version at
418
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
421
if [ -n "$BASH" ] ; then
424
local cur="${COMP_WORDS[COMP_CWORD]}"
425
COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
429
_cdvirtualenv_complete ()
432
# COMPREPLY=( $(compgen -d -- "${VIRTUAL_ENV}/${cur}" | sed -e "s@${VIRTUAL_ENV}/@@" ) )
433
COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
435
_cdsitepackages_complete ()
438
COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
440
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
441
complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
442
complete -o default -o nospace -F _virtualenvs workon
443
complete -o default -o nospace -F _virtualenvs rmvirtualenv
444
complete -o default -o nospace -F _virtualenvs cpvirtualenv
445
complete -o default -o nospace -F _virtualenvs showvirtualenv
446
elif [ -n "$ZSH_VERSION" ] ; then
447
compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv cpvirtualenv showvirtualenv
450
494
# Prints the Python version string for the current interpreter.
451
495
virtualenvwrapper_get_python_version () {
452
496
# Uses the Python from the virtualenv because we're trying to
517
561
virtualenvwrapper_verify_workon_home || return 1
518
562
virtualenvwrapper_verify_active_environment || return 1
519
563
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
520
cd "$site_packages"/$1
564
\cd "$site_packages"/$1
523
567
# Does a ``cd`` to the root of the currently-active virtualenv.
524
568
cdvirtualenv () {
525
569
virtualenvwrapper_verify_workon_home || return 1
526
570
virtualenvwrapper_verify_active_environment || return 1
530
574
# Shows the content of the site-packages directory of the currently-active
591
635
\cp -r "$source_env" "$target_env"
592
for script in $( \ls $target_env/bin/* )
636
for script in $( \ls $target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/* )
594
638
newscript="$script-new"
595
639
\sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
597
641
\chmod a+x "$script"
600
virtualenv "$target_env" --relocatable
601
\sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"
644
"$VIRTUALENVWRAPPER_VIRTUALENV" "$target_env" --relocatable
645
\sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" > "$target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
603
(cd "$WORKON_HOME" && (
647
(\cd "$WORKON_HOME" && (
604
648
virtualenvwrapper_run_hook "pre_cpvirtualenv" "$env_name" "$new_env";
605
649
virtualenvwrapper_run_hook "pre_mkvirtualenv" "$new_env"