Skip to content

Commit 533f415

Browse files
committed
Provide a way to extend the lazy-loader
Allow _VIRTUALENVWRAPPER_API to be extended before the lazy-loader defines the API functions that trigger the full loader. Patch contributed by John Purnell. Resolves issue #188. Signed-off-by: Doug Hellmann <[email protected]>
1 parent bb51351 commit 533f415

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

docs/source/history.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ dev
99
quoted. Addresses :bbissue:`164`.
1010
- Add :ref:`command-wipeenv` command for removing all packages
1111
installed in the virtualenv.
12+
- Allow users of ``virtualenvwrapper_lazy.sh`` to extend the list of
13+
API commands that trigger the lazy-loader by extending
14+
``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see
15+
:bbissue:`188`.
1216

1317
4.0
1418
===

tests/test_lazy_extending.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- mode: shell-script -*-
2+
3+
test_dir=$(cd $(dirname $0) && pwd)
4+
source "$test_dir/setup.sh"
5+
6+
oneTimeSetUp() {
7+
rm -rf "$WORKON_HOME"
8+
mkdir -p "$WORKON_HOME"
9+
[ ! -z "$ZSH_VERSION" ] && unsetopt shwordsplit
10+
}
11+
12+
oneTimeTearDown() {
13+
rm -rf "$WORKON_HOME"
14+
}
15+
16+
setUp () {
17+
echo
18+
rm -f "$test_dir/catch_output"
19+
}
20+
21+
function_defined_lazy() {
22+
name="$1"
23+
assertTrue "$name not defined" "type $name"
24+
assertTrue "$name does not load virtualenvwrapper" "typeset -f $name | grep 'virtualenvwrapper_load'"
25+
if [ "$name" = "mkvirtualenv" ]
26+
then
27+
lookfor="rmvirtualenv"
28+
else
29+
lookfor="mkvirtualenv"
30+
fi
31+
assertFalse "$name includes reference to $lookfor: $(typeset -f $name)" "typeset -f $name | grep $lookfor"
32+
}
33+
34+
test_custom_defined_lazy() {
35+
_VIRTUALENVWRAPPER_API="my_custom_command"
36+
source "$test_dir/../virtualenvwrapper_lazy.sh"
37+
function_defined_lazy my_custom_command
38+
}
39+
40+
. "$test_dir/shunit2"

virtualenvwrapper_lazy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# Alternative startup script for faster login times.
33

4-
export _VIRTUALENVWRAPPER_API="mkvirtualenv rmvirtualenv lsvirtualenv showvirtualenv workon add2virtualenv cdsitepackages cdvirtualenv lssitepackages toggleglobalsitepackages cpvirtualenv setvirtualenvproject mkproject cdproject mktmpenv"
4+
export _VIRTUALENVWRAPPER_API="$_VIRTUALENVWRAPPER_API mkvirtualenv rmvirtualenv lsvirtualenv showvirtualenv workon add2virtualenv cdsitepackages cdvirtualenv lssitepackages toggleglobalsitepackages cpvirtualenv setvirtualenvproject mkproject cdproject mktmpenv"
55

66
if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ]
77
then

0 commit comments

Comments
 (0)