Skip to content

Commit bb6c695

Browse files
author
Thomas Desvenain
committed
add testpackage setup.py
1 parent 17eec7b commit bb6c695

File tree

8 files changed

+105
-4
lines changed

8 files changed

+105
-4
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Features
1515

1616
1. Organizes all of your virtual environments in one place.
1717

18-
2. Wrappers for creating and deleting environments, including
18+
2. Wrappers for creating, copying and deleting environments, including
1919
user-configurable hooks.
2020

2121
3. Use a single command to switch between environments.

docsource/command_ref.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ Syntax::
3131

3232
rmvirtualenv ENVNAME
3333

34+
cpvirtualenv
35+
------------
36+
37+
Duplicate an environment, in the WORKON_HOME.
38+
39+
Syntax::
40+
41+
cpvirtualenv ENVNAME TARGETENVNAME
42+
3443
workon
3544
------
3645

docsource/developers.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ docs:
1919

2020
- Sphinx
2121
- Paver
22-
- sphinxcontrib.paverutils
22+
- docutils
23+
- sphinxcontrib-paverutils
2324

2425
Once all of them are installed into a virtualenv using easy_install,
2526
run ``paver html`` to generate the HTML version of the documentation::

docsource/history.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
===============
22
Release History
33
===============
4+
5+
- Added cpvirtualenv command [Thomas Desvenain]
46

57
1.24
68

tests/test.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ setUp () {
2121
rm -f "$test_dir/catch_output"
2222
}
2323

24+
tearDown() {
25+
echo
26+
}
27+
2428
test_mkvirtualenv() {
2529
mkvirtualenv "env1"
2630
assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
@@ -267,7 +271,7 @@ test_add2virtualenv_relative () {
267271
test_lssitepackages () {
268272
mkvirtualenv "lssitepackagestest"
269273
contents="$(lssitepackages)"
270-
assertTrue "No easy-install.pth in $contents" "echo $contents | grep easy-install.pth"
274+
assertTrue "No easy-install.pth in $/contents" "echo $contents | grep easy-install.pth"
271275
}
272276

273277
test_lssitepackages_add2virtualenv () {
@@ -279,5 +283,31 @@ test_lssitepackages_add2virtualenv () {
279283
assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
280284
}
281285

286+
test_cpvirtualenv () {
287+
mkvirtualenv "cpvirtualenvtest"
288+
$VIRTUAL_ENV/bin/easy_install "tests/testpackage"
289+
cpvirtualenv "cpvirtualenvtest" "cpvirtualenvcopy"
290+
deactivate
291+
rmvirtualenv "cpvirtualenvtest"
292+
workon "cpvirtualenvcopy"
293+
testscript="$(which testscript.py)"
294+
assertSame "$testscript" $(echo "$WORKON_HOME/cpvirtualenvcopy/bin/testscript.py")
295+
testscriptcontent="$(cat $testscript)"
296+
assertTrue "No cpvirtualenvtest in $/testscriptcontent" "echo $testscriptcontent | grep cpvirtualenvtest"
297+
assertTrue virtualenvwrapper_verify_active_environment
298+
assertSame "cpvirtualenvcopy" $(basename "$VIRTUAL_ENV")
299+
cdvirtualenv
300+
assertSame "$VIRTUAL_ENV" "$(pwd)"
301+
}
302+
303+
test_cprelocatablevirtualenv () {
304+
mkvirtualenv "cprelocatabletest"
305+
virtualenv --relocatable "$WORKON_HOME/cprelocatabletest"
306+
cpvirtualenv "cprelocatabletest" "cprelocatablecopy"
307+
assertTrue virtualenvwrapper_verify_active_environment
308+
assertSame "cprelocatablecopy" $(basename "$VIRTUAL_ENV")
309+
cdvirtualenv
310+
assertSame "$VIRTUAL_ENV" "$(pwd)"
311+
}
282312

283313
. "$test_dir/shunit2"

tests/testpackage/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Test package for virtualenvwrapper tests
2+
from setuptools import setup
3+
4+
version = '1.0'
5+
6+
setup(
7+
name='testpackage',
8+
version=version,
9+
description="Fake package",
10+
author="Ingeniweb",
11+
author_email='thomas.desvenain@gmail.com',
12+
url='http://pypi.python.org/pypi/testpackage/',
13+
)

tests/testpackage/testscript.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A test script
5+
"""
6+
7+
print "Hello world"

virtualenvwrapper_bashrc

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ if [ -n "$BASH" ] ; then
319319
complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
320320
complete -o default -o nospace -F _virtualenvs workon
321321
complete -o default -o nospace -F _virtualenvs rmvirtualenv
322+
complete -o default -o nospace -F _virtualenvs cpvirtualenv
322323
elif [ -n "$ZSH_VERSION" ] ; then
323-
compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv
324+
compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv cpvirtualenv
324325
fi
325326

326327
# Prints the Python version string for the current interpreter.
@@ -412,3 +413,41 @@ function lssitepackages () {
412413
cat "$path_file"
413414
fi
414415
}
416+
417+
function cpvirtualenv() {
418+
419+
typeset env_name="$1"
420+
if [ "$env_name" = "" ]
421+
then
422+
virtualenvwrapper_show_workon_options
423+
return 1
424+
fi
425+
typeset new_env="$2"
426+
if [ "$new_env" = "" ]
427+
then
428+
echo "Please specify target virtualenv"
429+
return 1
430+
fi
431+
if [echo "$WORKON_HOME" | grep -e "/$"]
432+
then
433+
env_home="$WORKON_HOME"
434+
else
435+
env_home="$WORKON_HOME/"
436+
fi
437+
source_env="$env_home$env_name"
438+
target_env="$env_home$new_env"
439+
440+
cp -r "$source_env" "$target_env"
441+
for script in $( ls $target_env/bin/* )
442+
do
443+
newscript="$script-new"
444+
sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
445+
mv "$newscript" "$script"
446+
chmod a+x "$script"
447+
done
448+
449+
virtualenv "$target_env" --relocatable
450+
sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"
451+
echo "Created $new_env virtualenv"
452+
workon "$new_env"
453+
}

0 commit comments

Comments
 (0)