~ubuntu-branches/ubuntu/trusty/virtualenvwrapper/trusty-proposed

« back to all changes in this revision

Viewing changes to virtualenvwrapper.sh

  • Committer: Bazaar Package Importer
  • Author(s): Jan Dittberner
  • Date: 2011-08-14 19:54:16 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110814195416-05rds6ctun2yc69a
Tags: 2.8-1
* New upstream version.
* refresh debian/patches/debianspecific-setup.py.patch
* debian/control: get rid of Build-Depends-Indep
* switch to dh_python2 and dh_sphinxdoc
  - debian/control:
     - remove Build-Depends python-support
     - bump Build-Depends python to 2.6.6-3~
     - bump Build-Depends python-spinx to 1.0.7+dfsg-1~
     - add ${sphinxdoc:Depends} and libjs-sphinxdoc to Depends
     - remove libjs-jquery from Depends
  - debian/rules:
     - add --with python2,sphinxdoc in debian/rules
     - don't dh_link jquery.js
     - don't remove _sources, .doctrees and jquery.js manually
* add japanese sphinx documentation
  - debian/rules: add ja to lang for loop
  - add debian/virtualenvwrapper.doc-base.ja
  - add /usr/share/doc/virtualenvwrapper/ja to debian/virtualenvwrapper.dirs
* debian/rules:
  - replace copies of sphinx's _static directory in ja and es with symlinks
    to en
  - simplify sphinx build and set language
* use upstream sphinx configuration and remove bitbucket usage via
  debian/patches/remove_bitbucket_support.patch
* don't compress .txt files, to enable sphinx doc search

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    VIRTUALENVWRAPPER_VIRTUALENV="virtualenv"
57
57
fi
58
58
 
 
59
# Define script folder depending on the platorm (Win32/Unix)
 
60
VIRTUALENVWRAPPER_ENV_BIN_DIR="bin"
 
61
if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
 
62
then
 
63
        # Only assign this for msys, cygwin use standard Unix paths
 
64
        # and its own python installation 
 
65
        VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
 
66
fi
 
67
 
59
68
virtualenvwrapper_derive_workon_home() {
60
69
    typeset workon_home_dir="$WORKON_HOME"
61
70
 
133
142
        echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
134
143
        return 1
135
144
    fi
 
145
    if [ -z "$VIRTUALENVWRAPPER_LOG_DIR" ]
 
146
    then
 
147
        echo "ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
 
148
        return 1
 
149
    fi
136
150
    "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
137
151
    result=$?
138
152
    
149
163
    return $result
150
164
}
151
165
 
 
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
 
170
        _virtualenvs () {
 
171
            local cur="${COMP_WORDS[COMP_CWORD]}"
 
172
            COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
 
173
        }
 
174
        _cdvirtualenv_complete () {
 
175
            local cur="$2"
 
176
            COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
 
177
        }
 
178
        _cdsitepackages_complete () {
 
179
            local cur="$2"
 
180
            COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
 
181
        }
 
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
 
189
        _virtualenvs () {
 
190
            reply=( $(virtualenvwrapper_show_workon_options) )
 
191
        }
 
192
        _cdvirtualenv_complete () {
 
193
            reply=( $(cdvirtualenv && ls -d ${1}*) )
 
194
        }
 
195
        _cdsitepackages_complete () {
 
196
            reply=( $(cdsitepackages && ls -d ${1}*) )
 
197
        }
 
198
        compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv 
 
199
        compctl -K _cdvirtualenv_complete cdvirtualenv
 
200
        compctl -K _cdsitepackages_complete cdsitepackages
 
201
    fi
 
202
}
 
203
 
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
174
226
        return 1
175
227
    fi
 
228
 
 
229
    virtualenvwrapper_setup_tab_completion
 
230
 
176
231
}
177
232
 
 
233
 
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" &&
 
280
    (
 
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"
228
 
        )
 
286
    )
229
287
    typeset RC=$?
230
288
    [ $RC -ne 0 ] && return $RC
231
289
 
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)"
261
 
    cd "$WORKON_HOME"
 
319
    \cd "$WORKON_HOME"
262
320
 
263
321
    virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
264
322
    \rm -rf "$env_dir"
267
325
    # If the directory we used to be in still exists, move back to it.
268
326
    if [ -d "$prior_dir" ]
269
327
    then
270
 
        cd "$prior_dir"
 
328
        \cd "$prior_dir"
271
329
    fi
272
330
}
273
331
 
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 '^\*$')
281
 
    
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 '^\*$')
 
339
 
 
340
#    (\cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
283
341
}
284
342
 
285
343
_lsvirtualenv_usage () {
293
351
#
294
352
# Usage: lsvirtualenv [-l]
295
353
lsvirtualenv () {
296
 
    typeset -a args
297
 
    args=($(getopt blh "$@"))
298
 
    if [ $? != 0 ]
299
 
    then
300
 
        _lsvirtualenv_usage
301
 
        return 1
302
 
    fi
 
354
    
303
355
    typeset long_mode=true
304
 
    for opt in $args
305
 
    do
306
 
        case "$opt" in
307
 
            -l) long_mode=true;;
308
 
            -b) long_mode=false;;
309
 
            -h) _lsvirtualenv_usage;
310
 
                return 1;;
311
 
        esac
312
 
    done
 
356
    if command -v "getopts" &> /dev/null 
 
357
    then
 
358
                # Use getopts when possible
 
359
        OPTIND=1
 
360
                while getopts ":blh" opt "$@"
 
361
                do
 
362
                        case "$opt" in
 
363
                                l) long_mode=true;;
 
364
                                b) long_mode=false;;
 
365
                                h)  _lsvirtualenv_usage;
 
366
                                        return 1;;
 
367
                                ?) echo "Invalid option: -$OPTARG" >&2;
 
368
                                        _lsvirtualenv_usage;
 
369
                                        return 1;;
 
370
                        esac
 
371
                done
 
372
    else
 
373
        # fallback on getopt for other shell
 
374
            typeset -a args
 
375
            args=($(getopt blh "$@"))
 
376
            if [ $? != 0 ]
 
377
            then
 
378
                _lsvirtualenv_usage
 
379
                return 1
 
380
            fi
 
381
            for opt in $args
 
382
            do
 
383
                case "$opt" in
 
384
                    -l) long_mode=true;;
 
385
                    -b) long_mode=false;;
 
386
                    -h) _lsvirtualenv_usage;
 
387
                        return 1;;
 
388
                esac
 
389
            done
 
390
    fi
313
391
 
314
392
    if $long_mode
315
393
    then
357
435
    virtualenvwrapper_verify_workon_home || return 1
358
436
    virtualenvwrapper_verify_workon_environment $env_name || return 1
359
437
    
360
 
    activate="$WORKON_HOME/$env_name/bin/activate"
 
438
    activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"
361
439
    if [ ! -f "$activate" ]
362
440
    then
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"
392
470
        
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")
395
473
        
396
474
        # Call the original function.
413
491
}
414
492
 
415
493
 
416
 
#
417
 
# Set up tab completion.  (Adapted from Arthur Koziel's version at 
418
 
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
419
 
420
 
 
421
 
if [ -n "$BASH" ] ; then
422
 
    _virtualenvs ()
423
 
    {
424
 
        local cur="${COMP_WORDS[COMP_CWORD]}"
425
 
        COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
426
 
    }
427
 
 
428
 
 
429
 
    _cdvirtualenv_complete ()
430
 
    {
431
 
        local cur="$2"
432
 
        # COMPREPLY=( $(compgen -d -- "${VIRTUAL_ENV}/${cur}" | sed -e "s@${VIRTUAL_ENV}/@@" ) )
433
 
        COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
434
 
    }
435
 
    _cdsitepackages_complete ()
436
 
    {
437
 
        local cur="$2"
438
 
        COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
439
 
    }
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
448
 
fi
449
 
 
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
521
565
}
522
566
 
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
527
 
    cd $VIRTUAL_ENV/$1
 
571
    \cd $VIRTUAL_ENV/$1
528
572
}
529
573
 
530
574
# Shows the content of the site-packages directory of the currently-active
589
633
    fi
590
634
 
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/* )
593
637
    do
594
638
        newscript="$script-new"
595
639
        \sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
597
641
        \chmod a+x "$script"
598
642
    done
599
643
 
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"
602
646
 
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"
606
650
        ))