File tree Expand file tree Collapse file tree 4 files changed +115
-0
lines changed Expand file tree Collapse file tree 4 files changed +115
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,32 @@ installed.
56
56
57
57
.. _requirements file format : http://www.pip-installer.org/en/latest/requirement-format.html
58
58
59
+ .. _command-mktmpenv :
60
+
61
+ mktmpenv
62
+ --------
63
+
64
+ Create a new virtualenv in the ``WORKON_HOME `` directory.
65
+
66
+ Syntax::
67
+
68
+ mktmpenv [ENVNAME]
69
+
70
+ If no environment name is given, a temporary unique name is generated.
71
+
72
+ ::
73
+
74
+ $ mktmpenv
75
+ Using real prefix '/Library/Frameworks/Python.framework/Versions/2.7'
76
+ New python executable in 1e513ac6-616e-4d56-9aa5-9d0a3b305e20/bin/python
77
+ Overwriting 1e513ac6-616e-4d56-9aa5-9d0a3b305e20/lib/python2.7/distutils/__init__.py
78
+ with new content
79
+ Installing distribute...............................................
80
+ ....................................................................
81
+ .................................................................done.
82
+ This is a temporary environment. It will be deleted when deactivated.
83
+ (1e513ac6-616e-4d56-9aa5-9d0a3b305e20) $
84
+
59
85
.. _command-lsvirtualenv :
60
86
61
87
lsvirtualenv
Original file line number Diff line number Diff line change 7
7
- Incorporated patch to add ``-d `` option to
8
8
:ref: `command-add2virtualenv `, contributed by :bbuser: `miracle2k `.
9
9
- Add ``-i `` option to :ref: `command-mkvirtualenv `.
10
+ - Add :ref: `command-mktmpenv ` command for creating temporary
11
+ environments that are automatically removed when they are
12
+ deactivated.
10
13
11
14
2.9
12
15
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ test_dir=$( cd $( dirname $0 ) && pwd)
4
+
5
+ export WORKON_HOME=" $( echo ${TMPDIR:-/ tmp} /WORKON_HOME | sed ' s|//|/|g' ) "
6
+
7
+
8
+ oneTimeSetUp () {
9
+ rm -rf " $WORKON_HOME "
10
+ mkdir -p " $WORKON_HOME "
11
+ source " $test_dir /../virtualenvwrapper.sh"
12
+ }
13
+
14
+ oneTimeTearDown () {
15
+ rm -rf " $WORKON_HOME "
16
+ }
17
+
18
+ setUp () {
19
+ echo
20
+ rm -f " $test_dir /catch_output"
21
+ }
22
+
23
+ test_mktmpenv_no_name () {
24
+ before=$( lsvirtualenv -b)
25
+ mktmpenv > /dev/null 2>&1
26
+ after=$( lsvirtualenv -b)
27
+ assertFalse " Environment was not created" " [ \" $before \" = \" $after \" ]"
28
+ }
29
+
30
+ test_mktmpenv_name () {
31
+ assertFalse " Environment already exists" " [ -d \" $WORKON_HOME /name-given-by-user\" ]"
32
+ mktmpenv name-given-by-user > /dev/null 2>&1
33
+ assertTrue " Environment was not created" " [ -d \" $WORKON_HOME /name-given-by-user\" ]"
34
+ assertSame $( basename " $VIRTUAL_ENV " ) " name-given-by-user"
35
+ }
36
+
37
+ test_deactivate () {
38
+ assertFalse " Environment already exists" " [ -d \" $WORKON_HOME /automatically-deleted\" ]"
39
+ mktmpenv automatically-deleted > /dev/null 2>&1
40
+ assertSame $( basename " $VIRTUAL_ENV " ) " automatically-deleted"
41
+ assertTrue " Environment was not created" " [ -d \" $WORKON_HOME /automatically-deleted\" ]"
42
+ deactivate > /dev/null 2>&1
43
+ assertFalse " Environment still exists" " [ -d \" $WORKON_HOME /automatically-deleted\" ]"
44
+ }
45
+
46
+ . " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -905,6 +905,46 @@ function cdproject {
905
905
return 0
906
906
}
907
907
908
+ #
909
+ # Temporary virtualenv
910
+ #
911
+ # Originally part of virtualenvwrapper.tmpenv plugin
912
+ #
913
+ mktmpenv () {
914
+ typeset tmpenvname
915
+
916
+ # Generate a unique temporary name, if one is not given.
917
+ if [ $# -eq 0 ]
918
+ then
919
+ tmpenvname=$( " $VIRTUALENVWRAPPER_PYTHON " -c ' import uuid; print uuid.uuid4()' )
920
+ mkvirtualenv " $tmpenvname "
921
+ else
922
+ mkvirtualenv " $@ "
923
+ fi
924
+
925
+ # Create the environment
926
+ RC=$?
927
+ if [ $RC -ne 0 ]
928
+ then
929
+ return $RC
930
+ fi
931
+
932
+ # Change working directory
933
+ cdvirtualenv
934
+
935
+ # Create the tmpenv marker file
936
+ echo " This is a temporary environment. It will be deleted when you run 'deactivate'." | tee " $VIRTUAL_ENV /README.tmpenv"
937
+
938
+ # Update the postdeactivate script
939
+ cat - >> " $VIRTUAL_ENV /bin/postdeactivate" << EOF
940
+ if [ -f "$VIRTUAL_ENV /README.tmpenv" ]
941
+ then
942
+ echo "Removing temporary environment:" $( basename " $VIRTUAL_ENV " )
943
+ rmvirtualenv $( basename " $VIRTUAL_ENV " )
944
+ fi
945
+ EOF
946
+ }
947
+
908
948
909
949
#
910
950
# Invoke the initialization hooks
You can’t perform that action at this time.
0 commit comments