Commits

Thomas Desvenain  committed fd037ad Merge

resolve conflict on tests dispatch

  • Participants
  • Parent commits da4fd43, 55a909e

Comments (0)

Files changed (18)

 e55e8a54de7be78b8400632ab004abb29aaa8899 1.23
 b243d023094b6b0ef1b834dcc100f8c342c67537 1.24
 4a8870326d84f97d5539b586b21419ba330fea48 1.24.1
+f318697791416cf0897091718d542e8045854233 1.24.2
+06229877a640ecb490faf46f923d8be916a0ebed 1.25
+51eef82a39d431cee156fea7005fa1631e21655e 1.26

File docsource/command_ref.rst

 
 Because the exact path to the site-packages directory in the virtualenv depends on the
 version of Python, ``cdsitepackages`` is provided as a shortcut for ``cdvirtualenv
-lib/python${pyvers}/site-packages``.
+lib/python${pyvers}/site-packages``. An optional argument is also allowed, to specify 
+a directory hierarchy within the ``site-packages`` directory to change into.
+
+::
+  $ workon pymotw
+  $ echo $VIRTUAL_ENV
+  /Users/dhellmann/.virtualenvs/pymotw
+  $ cdsitepackages PyMOTW/bisect/
+  $ pwd
+  /Users/dhellmann/.virtualenvs/pymotw/lib/python2.6/site-packages/PyMOTW/bisect
 
 ===============
 Path Management

File docsource/history.rst

   
   - Added cpvirtualenv command [Thomas Desvenain]
 
+1.26
+
+  - Fix a problem with error messages showing up during init for users
+    with the wrappers installed site-wide but who are not actually
+    using them.  See issue #26.
+  - Split up the tests into multiple files.
+  - Run all tests with all supported shells.
+
+1.25
+
+  - Merged in changes to cdsitepackages from William McVey.  It now
+    takes an argument and supports tab-completion for directories
+    within site-packages.
+
+1.24.2
+
+  - Add user provided :ref:`tips-and-tricks` section.
+  - Add link to Rich Leland's screencast to :ref:`references` section.
+
+1.24.1
+
+  - Add license text to the header of the script.
+
 1.24
 
   - Resolve a bug with the preactivate hook not being run properly.

File docsource/index.rst

    history
    developers
 
+.. _references:
+
 ==========
 References
 ==========

File docsource/tips.rst

+.. _tips-and-tricks:
+
 =================
  Tips and Tricks
 =================
 
 # What project are we building?
 PROJECT = 'virtualenvwrapper'
-VERSION = '1.24.1'
+VERSION = '1.26'
 os.environ['VERSION'] = VERSION
 
 # Read the long description to give to setup
 
 @task
 def test():
-    sh('bash ./tests/test.sh')
-    sh('SHUNIT_PARENT=./tests/test.sh zsh -o shwordsplit ./tests/test.sh')
-    sh('bash ./tests/test_misconfigured.sh')
+    #test_scripts = glob.glob('./tests/test*.sh')
+    test_scripts = path('tests').glob('test*.sh')
+    print test_scripts
+    for shell_cmd in [ 'bash', 'sh', 'SHUNIT_PARENT=%(test_script)s zsh -o shwordsplit' ]:
+        for test_script in test_scripts:
+            base_cmd = shell_cmd + ' %(test_script)s'
+            cmd = base_cmd % locals()
+            print '*' * 80
+            print
+            sh(cmd)
     return

File tests/manual_test_install.sh

+#!/bin/sh
+#
+# Test installation of virtualenvwrapper in a new virtualenv.
+#
+
+test_dir=$(dirname $0)
+dist_dir="$1"
+version="$2"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+mkvirtualenv "installtest"
+pip install "$dist_dir/virtualenvwrapper-$version.tar.gz"
+RC=$?
+
+rm -rf "$WORKON_HOME"
+exit $RC

File tests/test_add2virtualenv.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_add2virtualenv () {
+    mkvirtualenv "pathtest"
+    add2virtualenv "/full/path"
+    cdsitepackages
+    path_file="./virtualenv_path_extensions.pth"
+    assertTrue "No /full/path in `cat $path_file`" "grep /full/path $path_file"
+    cd -
+}
+
+test_add2virtualenv_relative () {
+    mkvirtualenv "pathtest"
+    parent_dir=$(dirname $(pwd))
+    base_dir=$(basename $(pwd))
+    add2virtualenv "../$base_dir"
+    cdsitepackages
+    path_file="./virtualenv_path_extensions.pth"
+    assertTrue "No $parent_dir/$base_dir in \"`cat $path_file`\"" "grep \"$parent_dir/$base_dir\" $path_file"
+    cd - >/dev/null 2>&1
+}
+
+
+. "$test_dir/shunit2"

File tests/test_cd.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_cdvirtual() {
+    pushd "$(pwd)" >/dev/null
+    cdvirtualenv
+    assertSame "$VIRTUAL_ENV" "$(pwd)"
+    cdvirtualenv bin
+    assertSame "$VIRTUAL_ENV/bin" "$(pwd)"
+    popd >/dev/null
+}
+
+test_cdsitepackages () {
+    pushd "$(pwd)" >/dev/null   
+    cdsitepackages
+    pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
+    sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
+    assertSame "$sitepackages" "$(pwd)"
+    popd >/dev/null
+}
+
+test_cdsitepackages_with_arg () {
+    pushd "$(pwd)" >/dev/null
+    pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
+    sitepackage_subdir="$VIRTUAL_ENV/lib/python${pyvers}/site-packages/subdir"
+    mkdir -p "${sitepackage_subdir}"
+    cdsitepackages subdir
+    assertSame "$sitepackage_subdir" "$(pwd)"
+    popd >/dev/null
+}
+
+test_cdvirtualenv_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`cdvirtualenv 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+test_cdsitepackages_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`cdsitepackages 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+
+. "$test_dir/shunit2"

File tests/test_cp.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+
+test_cpvirtualenv () {
+    mkvirtualenv "cpvirtualenvtest"
+    $VIRTUAL_ENV/bin/easy_install "tests/testpackage"
+    cpvirtualenv "cpvirtualenvtest" "cpvirtualenvcopy"
+    deactivate
+    rmvirtualenv "cpvirtualenvtest"
+    workon "cpvirtualenvcopy"
+    testscript="$(which testscript.py)"
+    assertSame "$testscript" $(echo "$WORKON_HOME/cpvirtualenvcopy/bin/testscript.py")
+    testscriptcontent="$(cat $testscript)"
+    assertTrue "No cpvirtualenvtest in $/testscriptcontent" "echo $testscriptcontent | grep cpvirtualenvtest"
+    assertTrue virtualenvwrapper_verify_active_environment
+    assertSame "cpvirtualenvcopy" $(basename "$VIRTUAL_ENV")
+    cdvirtualenv
+    assertSame "$VIRTUAL_ENV" "$(pwd)"
+}
+
+test_cprelocatablevirtualenv () {
+    mkvirtualenv "cprelocatabletest"
+    virtualenv --relocatable "$WORKON_HOME/cprelocatabletest"
+    cpvirtualenv "cprelocatabletest" "cprelocatablecopy"
+    assertTrue virtualenvwrapper_verify_active_environment
+    assertSame "cprelocatablecopy" $(basename "$VIRTUAL_ENV")
+    cdvirtualenv
+    assertSame "$VIRTUAL_ENV" "$(pwd)"
+}
+
+
+. "$test_dir/shunit2"
+

File tests/test_install.sh

-#!/bin/sh
-#
-# Test installation of virtualenvwrapper in a new virtualenv.
-#
-
-test_dir=$(dirname $0)
-dist_dir="$1"
-version="$2"
-
-export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
-mkvirtualenv "installtest"
-easy_install "$dist_dir/virtualenvwrapper-$version.tar.gz"
-RC=$?
-
-rm -rf "$WORKON_HOME"
-exit $RC

File tests/test_ls.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_lssitepackages () {
+    mkvirtualenv "lssitepackagestest"
+    contents="$(lssitepackages)"    
+    assertTrue "No easy-install.pth in $contents" "echo $contents | grep easy-install.pth"
+}
+
+test_lssitepackages_add2virtualenv () {
+    mkvirtualenv "lssitepackagestest"
+    parent_dir=$(dirname $(pwd))
+    base_dir=$(basename $(pwd))
+    add2virtualenv "../$base_dir"
+    contents="$(lssitepackages)"    
+    assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
+}
+
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`lssitepackages should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+
+. "$test_dir/shunit2"

File tests/test_misconfigured.sh

-#!/bin/sh
-
-#set -x
-
-test_dir=$(dirname $0)
-
-export SCRATCH_DIR="${TMPDIR:-/tmp}/$$"
-
-oneTimeSetUp() {
-    rm -rf "$SCRATCH_DIR"
-    mkdir -p "$SCRATCH_DIR"
-}
-
-oneTimeTearDown() {
-    rm -rf "$SCRATCH_DIR"
-}
-
-test_workon_home_missing_bash () {
-    export WORKON_HOME="$SCRATCH_DIR/no_such_subdir"
-    bash -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_workon_home_missing_zsh () {
-    export WORKON_HOME="$SCRATCH_DIR/no_such_subdir"
-    zsh -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_shell_expansion_fails_bash () {
-    export WORKON_HOME="$SCRATCH_DIR/\$no_such_var"
-    bash -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_shell_expansion_fails_zsh () {
-    export WORKON_HOME="$SCRATCH_DIR/\$no_such_var"
-    zsh -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-. "$test_dir/shunit2"

File tests/test_mkvirtualenv.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_create() {
+    mkvirtualenv "env1"
+    assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
+    for hook in postactivate predeactivate postdeactivate
+    do
+        assertTrue "env1 $hook was not created" "[ -f $WORKON_HOME/env1/bin/$hook ]"
+        assertTrue "env1 $hook is not executable" "[ -x $WORKON_HOME/env1/bin/$hook ]"
+    done
+}
+
+test_activates () {
+    mkvirtualenv "env2"
+    assertTrue virtualenvwrapper_verify_active_environment
+    assertSame "env2" $(basename "$VIRTUAL_ENV")
+}
+
+test_hooks () {
+    export pre_test_dir=$(cd "$test_dir"; pwd)
+    echo "echo GLOBAL premkvirtualenv >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
+    chmod +x "$WORKON_HOME/premkvirtualenv"
+    echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
+    mkvirtualenv "env3"
+    output=$(cat "$test_dir/catch_output")
+    expected="GLOBAL premkvirtualenv
+GLOBAL postmkvirtualenv"
+    assertSame "$expected" "$output"
+    rm -f "$WORKON_HOME/premkvirtualenv"
+    rm -f "$WORKON_HOME/postmkvirtualenv"
+    deactivate
+    rmvirtualenv "env3"
+}
+
+test_no_virtualenv () {
+    old_path="$PATH"
+    PATH="/usr/bin:/bin:/usr/sbin:/sbin"
+    mkvirtualenv should_not_be_created 2>/dev/null
+    RC=$?
+    # Restore the path before testing because
+    # the test script depends on commands in the
+    # path.
+    export PATH="$old_path"
+    assertSame "$RC" "1"
+}
+
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`mkvirtualenv should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+# test_mkvirtualenv_sitepackages () {
+#     # Without the option verify that site-packages are copied.
+#     mkvirtualenv "env3"
+#     assertSame "env3" "$(basename $VIRTUAL_ENV)"
+#     pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
+#     sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
+#     #cat "$sitepackages/easy-install.pth"
+#     assertTrue "Do not have expected virtualenv.py" "[ -f $sitepackages/virtualenv.py ]"
+#     rmvirtualenv "env3"
+#     
+#     # With the argument, verify that they are not copied.
+#     mkvirtualenv --no-site-packages "env4"
+#     assertSame "env4" $(basename "$VIRTUAL_ENV")
+#     pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
+#     sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
+#     assertTrue "[ -f $sitepackages/setuptools.pth ]"
+#     assertTrue "[ -f $sitepackages/easy-install.pth ]"
+#     assertFalse "Have virtualenv.py but should not" "[ -f $sitepackages/virtualenv.py ]"    
+#     rmvirtualenv "env4"
+# }
+
+
+. "$test_dir/shunit2"

File tests/test_rmvirtualenv.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_remove () {
+    mkvirtualenv "deleteme"
+    assertTrue "[ -d $WORKON_HOME/deleteme ]"
+    deactivate
+    rmvirtualenv "deleteme"
+    assertFalse "[ -d $WORKON_HOME/deleteme ]"
+}
+
+test_no_such_env () {
+    assertFalse "[ -d $WORKON_HOME/deleteme ]"
+    assertTrue "rmvirtualenv deleteme"
+}
+
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`rmvirtualenv should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+
+. "$test_dir/shunit2"

File tests/test_run_hook.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_virtualenvwrapper_run_hook() {
+    echo "echo run >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/test_hook"
+    chmod +x "$WORKON_HOME/test_hook"
+    virtualenvwrapper_run_hook "$WORKON_HOME/test_hook"
+    output=$(cat "$test_dir/catch_output")
+    expected="run"
+    assertSame "$expected" "$output"
+}
+
+test_virtualenvwrapper_run_hook_permissions() {
+    echo "echo run >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/test_hook"
+    chmod -x "$WORKON_HOME/test_hook"
+    virtualenvwrapper_run_hook "$WORKON_HOME/test_hook"
+    output=$(cat "$test_dir/catch_output")
+    expected=""
+    assertSame "$expected" "$output"
+}
+
+. "$test_dir/shunit2"

File tests/test_workon.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+source "$test_dir/../virtualenvwrapper_bashrc"
+
+export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+    mkvirtualenv "env1"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+}
+
+test_workon () {
+    workon env1
+    assertTrue virtualenvwrapper_verify_active_environment
+    assertSame "env1" $(basename "$VIRTUAL_ENV")
+}
+
+test_workon_activate_hooks () {
+    for t in pre post
+    do
+        echo "echo GLOBAL ${t}activate >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/${t}activate"
+        chmod +x "$WORKON_HOME/${t}activate"
+        echo "echo ENV ${t}activate >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/env1/bin/${t}activate"
+        chmod +x "$WORKON_HOME/env1/bin/${t}activate"
+    done
+
+    rm "$test_dir/catch_output"
+
+    workon env1
+    
+    output=$(cat "$test_dir/catch_output")
+    expected="GLOBAL preactivate
+ENV preactivate
+GLOBAL postactivate
+ENV postactivate"
+
+    assertSame "$expected"  "$output"
+    
+    for t in pre post
+    do
+        rm -f "$WORKON_HOME/env1/bin/${t}activate"
+        rm -f "$WORKON_HOME/${t}activate"
+    done
+}
+
+test_deactivate () {
+    workon env1
+    assertNotNull "$VIRTUAL_ENV"
+    deactivate
+    assertNull "$VIRTUAL_ENV"
+    assertFalse virtualenvwrapper_verify_active_environment    
+}
+
+test_deactivate_hooks () {
+    workon env1
+
+    for t in pre post
+    do
+        echo "echo GLOBAL ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/${t}deactivate"
+        echo "echo ENV ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
+    done
+
+    deactivate
+
+    output=$(cat "$test_dir/catch_output")
+    expected="ENV predeactivate
+GLOBAL predeactivate
+ENV postdeactivate
+GLOBAL postdeactivate"
+    assertSame "$expected" "$output"
+    
+    for t in pre post
+    do
+        rm -f "$WORKON_HOME/env1/bin/${t}activate"
+        rm -f "$WORKON_HOME/${t}activate"
+    done
+}
+
+test_virtualenvwrapper_show_workon_options () {
+    mkdir "$WORKON_HOME/not_env"
+    (cd "$WORKON_HOME"; ln -s env1 link_env)
+    envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ')
+    assertSame "env1 link_env " "$envs"
+    rmdir "$WORKON_HOME/not_env"
+    rm -f "$WORKON_HOME/link_env"
+}
+
+test_virtualenvwrapper_show_workon_options_no_envs () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME=${TMPDIR:-/tmp}/$$
+    envs=$(virtualenvwrapper_show_workon_options 2>/dev/null | tr '\n' ' ')
+    assertSame "" "$envs"
+    export WORKON_HOME="$old_home"
+}
+
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`workon should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+. "$test_dir/shunit2"

File virtualenvwrapper_bashrc

 function virtualenvwrapper_verify_workon_home () {
     if [ ! -d "$WORKON_HOME" ]
     then
-        echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist." >&2
+        [ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist.  Create it or set WORKON_HOME to an existing directory." >&2
         return 1
     fi
     return 0
 
 # Set up virtualenvwrapper properly
 function virtualenvwrapper_initialize () {
-    virtualenvwrapper_verify_workon_home || return 1
+    virtualenvwrapper_verify_workon_home -q || return 1
     # mkvirtualenv
     virtualenvwrapper_make_hook "$WORKON_HOME/premkvirtualenv" \
         "This hook is run after a new virtualenv is created and before it is activated."
         # COMPREPLY=( $(compgen -d -- "${VIRTUAL_ENV}/${cur}" | sed -e "s@${VIRTUAL_ENV}/@@" ) )
         COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
     }
+    _cdsitepackages_complete ()
+    {
+        local cur="$2"
+        COMPREPLY=( $(cdsitepackages && compgen -d -- "${cur}" ) )
+    }
     complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
+    complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages
     complete -o default -o nospace -F _virtualenvs workon
     complete -o default -o nospace -F _virtualenvs rmvirtualenv
     complete -o default -o nospace -F _virtualenvs cpvirtualenv
 # created first.
 function add2virtualenv () {
 
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
 # Does a ``cd`` to the site-packages directory of the currently-active
 # virtualenv.
 function cdsitepackages () {
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
-    cd "$site_packages"
+    cd "$site_packages"/$1
 }
 
 # Does a ``cd`` to the root of the currently-active virtualenv.
 function cdvirtualenv () {
+    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_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
     ls $@ $site_packages