Commits

Thomas Desvenain  committed bb6c695

add testpackage setup.py

  • Participants
  • Parent commits 17eec7b

Comments (0)

Files changed (8)

 
 1.  Organizes all of your virtual environments in one place.
 
-2.  Wrappers for creating and deleting environments, including
+2.  Wrappers for creating, copying and deleting environments, including
     user-configurable hooks.
 
 3.  Use a single command to switch between environments.

File docsource/command_ref.rst

 
     rmvirtualenv ENVNAME
 
+cpvirtualenv
+------------
+
+Duplicate an environment, in the WORKON_HOME.
+
+Syntax::
+
+    cpvirtualenv ENVNAME TARGETENVNAME
+
 workon
 ------
 

File docsource/developers.rst

 
 - Sphinx
 - Paver
-- sphinxcontrib.paverutils
+- docutils
+- sphinxcontrib-paverutils
 
 Once all of them are installed into a virtualenv using easy_install,
 run ``paver html`` to generate the HTML version of the documentation::

File docsource/history.rst

 ===============
 Release History
 ===============
+  
+  - Added cpvirtualenv command [Thomas Desvenain]
 
 1.24
 

File tests/test.sh

     rm -f "$test_dir/catch_output"
 }
 
+tearDown() {
+    echo
+}
+
 test_mkvirtualenv() {
     mkvirtualenv "env1"
     assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
 test_lssitepackages () {
     mkvirtualenv "lssitepackagestest"
     contents="$(lssitepackages)"    
-    assertTrue "No easy-install.pth in $contents" "echo $contents | grep easy-install.pth"
+    assertTrue "No easy-install.pth in $/contents" "echo $contents | grep easy-install.pth"
 }
 
 test_lssitepackages_add2virtualenv () {
     assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
 }
 
+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/testpackage/setup.py

+# Test package for virtualenvwrapper tests
+from setuptools import setup
+
+version = '1.0'
+
+setup(
+    name='testpackage',
+    version=version,
+    description="Fake package",
+    author="Ingeniweb",
+    author_email='thomas.desvenain@gmail.com',
+    url='http://pypi.python.org/pypi/testpackage/',
+    )

File tests/testpackage/testscript.py

+#!/usr/bin/env python
+
+"""
+A test script
+"""
+
+print "Hello world"

File virtualenvwrapper_bashrc

     complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
     complete -o default -o nospace -F _virtualenvs workon
     complete -o default -o nospace -F _virtualenvs rmvirtualenv
+    complete -o default -o nospace -F _virtualenvs cpvirtualenv
 elif [ -n "$ZSH_VERSION" ] ; then
-    compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv
+    compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv cpvirtualenv
 fi
 
 # Prints the Python version string for the current interpreter.
         cat "$path_file"
     fi
 }
+
+function cpvirtualenv() {
+
+    typeset env_name="$1"
+    if [ "$env_name" = "" ]
+    then
+        virtualenvwrapper_show_workon_options
+        return 1
+    fi
+    typeset new_env="$2"
+    if [ "$new_env" = "" ]
+    then
+        echo "Please specify target virtualenv"
+        return 1
+    fi
+    if [echo "$WORKON_HOME" | grep -e "/$"]
+    then
+        env_home="$WORKON_HOME"
+    else
+        env_home="$WORKON_HOME/"
+    fi
+    source_env="$env_home$env_name"
+    target_env="$env_home$new_env"
+
+    cp -r "$source_env" "$target_env"
+    for script in $( ls $target_env/bin/* )
+      do
+        newscript="$script-new"
+        sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
+        mv "$newscript" "$script"
+        chmod a+x "$script"
+      done
+
+    virtualenv "$target_env" --relocatable
+    sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"
+    echo "Created $new_env virtualenv"
+    workon "$new_env"
+}