Commits

Anonymous committed d2abc35

delay initialization until first api function is called

Comments (0)

Files changed (1)

virtualenvwrapper.sh

 # 11. The virtual environment is activated.
 #
 
+VIRTUALENVWRAPPER_INITIALIZED=0
+
 # Locate the global Python where virtualenvwrapper is installed.
 if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
 then
 
 # Set up virtualenvwrapper properly
 function virtualenvwrapper_initialize {
+    # Only initialize once
+    [ $VIRTUALENVWRAPPER_INITIALIZED -eq 0 ] || return 1
+
     export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
 
     virtualenvwrapper_verify_workon_home -q || return 1
     fi
 
     virtualenvwrapper_setup_tab_completion
-
+    VIRTUALENVWRAPPER_INITIALIZED=1
     return 0
 }
 
 # (where the options are passed directly to virtualenv)
 #
 function mkvirtualenv {
+    virtualenvwrapper_initialize
+
     typeset -a in_args
     typeset -a out_args
     typeset -i i
 
 # Remove an environment, in the WORKON_HOME.
 function rmvirtualenv {
+    virtualenvwrapper_initialize
+
     typeset env_name="$1"
     virtualenvwrapper_verify_workon_home || return 1
     if [ "$env_name" = "" ]
 #
 # Usage: lsvirtualenv [-l]
 function lsvirtualenv {
+    virtualenvwrapper_initialize
     
     typeset long_mode=true
     if command -v "getopts" &> /dev/null 
 #
 # Usage: showvirtualenv [env]
 function showvirtualenv {
+    virtualenvwrapper_initialize
+
     typeset env_name="$1"
     if [ -z "$env_name" ]
     then
 # Usage: workon [environment_name]
 #
 function workon {
+  virtualenvwrapper_initialize
+
 	typeset env_name="$1"
 	if [ "$env_name" = "" ]
     then
 # site-packages directory; if this file does not exist, it will be
 # created first.
 function add2virtualenv {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     
 # Does a ``cd`` to the site-packages directory of the currently-active
 # virtualenv.
 function cdsitepackages {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
 
 # Does a ``cd`` to the root of the currently-active virtualenv.
 function cdvirtualenv {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     \cd $VIRTUAL_ENV/$1
 # Shows the content of the site-packages directory of the currently-active
 # virtualenv
 function lssitepackages {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
 # Toggles the currently-active virtualenv between having and not having
 # access to the global site-packages.
 function toggleglobalsitepackages {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
 
 # Duplicate the named virtualenv to make a new one.
 function cpvirtualenv {
+    virtualenvwrapper_initialize
     typeset env_name="$1"
     if [ "$env_name" = "" ]
     then
 # set the virtualenv up to be associated with the 
 # project
 function setvirtualenvproject {
+    virtualenvwrapper_initialize
     typeset venv="$1"
     typeset prj="$2"
     if [ -z "$venv" ]
 
 # Create a new project directory and its associated virtualenv.
 function mkproject {
+    virtualenvwrapper_initialize
     typeset -a in_args
     typeset -a out_args
     typeset -i i
 
 # Change directory to the active project
 function cdproject {
+    virtualenvwrapper_initialize
     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]
 # Originally part of virtualenvwrapper.tmpenv plugin
 #
 mktmpenv() {
+    virtualenvwrapper_initialize
     typeset tmpenvname
     typeset RC
 
 fi
 EOF
 }
-
-
-#
-# Invoke the initialization hooks
-#
-virtualenvwrapper_initialize
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.