Commits

Doug Hellmann committed 533f415

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 <doug.hellmann@gmail.com>

  • Participants
  • Parent commits bb51351

Comments (0)

Files changed (3)

docs/source/history.rst

   quoted. Addresses :bbissue:`164`.
 - Add :ref:`command-wipeenv` command for removing all packages
   installed in the virtualenv.
+- Allow users of ``virtualenvwrapper_lazy.sh`` to extend the list of
+  API commands that trigger the lazy-loader by extending
+  ``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see
+  :bbissue:`188`.
 
 4.0
 ===

tests/test_lazy_extending.sh

+# -*- mode: shell-script -*-
+
+test_dir=$(cd $(dirname $0) && pwd)
+source "$test_dir/setup.sh"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+    [ ! -z "$ZSH_VERSION" ] && unsetopt shwordsplit
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+function_defined_lazy() {
+    name="$1"
+    assertTrue "$name not defined" "type $name"
+	assertTrue "$name does not load virtualenvwrapper" "typeset -f $name | grep 'virtualenvwrapper_load'"
+    if [ "$name" = "mkvirtualenv" ]
+    then
+        lookfor="rmvirtualenv"
+    else
+        lookfor="mkvirtualenv"
+    fi
+	assertFalse "$name includes reference to $lookfor: $(typeset -f $name)" "typeset -f $name | grep $lookfor"
+}
+
+test_custom_defined_lazy() {
+    _VIRTUALENVWRAPPER_API="my_custom_command"
+    source "$test_dir/../virtualenvwrapper_lazy.sh"
+    function_defined_lazy my_custom_command
+}
+
+. "$test_dir/shunit2"

virtualenvwrapper_lazy.sh

 #!/bin/sh
 # Alternative startup script for faster login times.
 
-export _VIRTUALENVWRAPPER_API="mkvirtualenv rmvirtualenv lsvirtualenv showvirtualenv workon add2virtualenv cdsitepackages cdvirtualenv lssitepackages toggleglobalsitepackages cpvirtualenv setvirtualenvproject mkproject cdproject mktmpenv"
+export _VIRTUALENVWRAPPER_API="$_VIRTUALENVWRAPPER_API mkvirtualenv rmvirtualenv lsvirtualenv showvirtualenv workon add2virtualenv cdsitepackages cdvirtualenv lssitepackages toggleglobalsitepackages cpvirtualenv setvirtualenvproject mkproject cdproject mktmpenv"
 
 if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ]
 then