File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ oneTimeTearDown() {
20
20
setUp () {
21
21
echo
22
22
rm -f " $test_dir /catch_output"
23
+ echo " #!/bin/sh" > " $WORKON_HOME /preactivate"
24
+ echo " #!/bin/sh" > " $WORKON_HOME /postactivate"
23
25
}
24
26
25
27
test_associate () {
@@ -31,4 +33,40 @@ test_associate() {
31
33
assertEquals " $ptrfile contains wrong content" " $project " " $( cat $ptrfile ) "
32
34
}
33
35
36
+ test_preactivate () {
37
+ project=" /dev/null"
38
+ env=" env2"
39
+ ptrfile=" $WORKON_HOME /$env /.project"
40
+ cat - > " $WORKON_HOME /preactivate" << EOF
41
+ #!/bin/sh
42
+ if [ -f "$ptrfile " ]
43
+ then
44
+ echo exists >> "$test_dir /catch_output"
45
+ else
46
+ echo noexists >> "$test_dir /catch_output"
47
+ fi
48
+ EOF
49
+ chmod +x " $WORKON_HOME /preactivate"
50
+ mkvirtualenv -a " $project " " $env " > /dev/null 2>&1
51
+ assertSame " preactivate did not find file" " exists" " $( cat $test_dir /catch_output) "
52
+ }
53
+
54
+ test_postactivate () {
55
+ project=" /dev/null"
56
+ env=" env3"
57
+ ptrfile=" $WORKON_HOME /$env /.project"
58
+ cat - > " $WORKON_HOME /postactivate" << EOF
59
+ #!/bin/sh
60
+ if [ -f "$ptrfile " ]
61
+ then
62
+ echo exists >> "$test_dir /catch_output"
63
+ else
64
+ echo noexists >> "$test_dir /catch_output"
65
+ fi
66
+ EOF
67
+ chmod +x " $WORKON_HOME /postactivate"
68
+ mkvirtualenv -a " $project " " $env " > /dev/null 2>&1
69
+ assertSame " postactivate did not find file" " exists" " $( cat $test_dir /catch_output) "
70
+ }
71
+
34
72
. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -373,6 +373,14 @@ function mkvirtualenv {
373
373
# the environment won't exist. Use that to tell whether
374
374
# we should switch to the environment and run the hook.
375
375
[ ! -d " $WORKON_HOME /$envname " ] && return 0
376
+
377
+ # If they gave us a project directory, set it up now
378
+ # so the activate hooks can find it.
379
+ if [ ! -z " $project " ]
380
+ then
381
+ setvirtualenvproject " $WORKON_HOME /$envname " " $project "
382
+ fi
383
+
376
384
# Now activate the new environment
377
385
workon " $envname "
378
386
@@ -386,11 +394,6 @@ function mkvirtualenv {
386
394
pip install $a
387
395
done
388
396
389
- if [ ! -z " $project " ]
390
- then
391
- setvirtualenvproject " " " $project "
392
- fi
393
-
394
397
virtualenvwrapper_run_hook " post_mkvirtualenv"
395
398
}
396
399
You can’t perform that action at this time.
0 commit comments