File tree Expand file tree Collapse file tree 6 files changed +62
-1
lines changed Expand file tree Collapse file tree 6 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 1
1
CHANGES
2
2
=======
3
3
4
+ Next
5
+ ----
6
+
7
+ * Look for `./.virtualenvwrapper/postactivate ` and
8
+ `./.virtualenvwrapper/predeactivate ` hook scripts.
9
+
4
10
6.0.0.0a5
5
11
---------
6
12
Original file line number Diff line number Diff line change @@ -31,6 +31,22 @@ site, combine the :ref:`templates-bitbucket` and
31
31
32
32
$ mkproject -t bitbucket -t django my_site
33
33
34
+ Project Hook Files
35
+ ==================
36
+
37
+ The project directory can include additional hook files for the
38
+ `postactivate ` and `predeactivate ` hooks. Placing hook scripts in the
39
+ project hook directory, `.virtualenvwrapper `, allows them to be
40
+ checked into version control and shared more easily.
41
+
42
+ When the :ref: `scripts-postactivate ` hook runs, it looks for
43
+ `.virtualenvwrapper/postactivate ` within the project directory and if
44
+ it is found it sources the file.
45
+
46
+ When the :ref: `scripts-predeactivate ` hook runs, it looks for
47
+ `.virtualenvwrapper/predeactivate ` within the project directory and if
48
+ it is found it sources the file.
49
+
34
50
.. seealso ::
35
51
36
52
* :ref: `extensions-templates `
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ project = "virtualenvwrapper.project:post_activate_source"
93
93
user_scripts = " virtualenvwrapper.user_scripts:post_activate_source"
94
94
95
95
[project .entry-points ."virtualenvwrapper .pre_deactivate_source" ]
96
+ project = " virtualenvwrapper.project:pre_deactivate_source"
96
97
user_scripts = " virtualenvwrapper.user_scripts:pre_deactivate_source"
97
98
98
99
[project .entry-points ."virtualenvwrapper .post_deactivate_source" ]
Original file line number Diff line number Diff line change @@ -52,4 +52,24 @@ test_virtualenvwrapper_verify_project_home_missing_dir() {
52
52
PROJECT_HOME=" $old_home "
53
53
}
54
54
55
+ test_virtualenvwrapper_postactivate_hook () {
56
+ load_wrappers
57
+ mkproject " test_project_hook"
58
+ mkdir .virtualenvwrapper
59
+ echo " export TEST_PROJECT_HOOK_VAR=true" > .virtualenvwrapper/postactivate
60
+ echo " unset TEST_PROJECT_HOOK_VAR" > .virtualenvwrapper/predeactivate
61
+ deactivate
62
+
63
+ # Variable should not be set to start
64
+ assertSame " ${TEST_PROJECT_HOOK_VAR} " " "
65
+
66
+ # Activating the env should set it
67
+ workon " test_project_hook"
68
+ assertSame " true" " ${TEST_PROJECT_HOOK_VAR} "
69
+
70
+ # Deactivating should unset it
71
+ deactivate
72
+ assertSame " " " ${TEST_PROJECT_HOOK_VAR} "
73
+ }
74
+
55
75
. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ setenv =
23
23
deps = .[linter]
24
24
commands = flake8 virtualenvwrapper docs/source/conf.py
25
25
26
+ [flake8]
27
+ max-line-length = 200
28
+
26
29
[testenv:zsh]
27
30
setenv =
28
31
USING_TOX = 1
Original file line number Diff line number Diff line change 8
8
import logging
9
9
import os
10
10
11
- from virtualenvwrapper .user_scripts import make_hook , run_global , PERMISSIONS
11
+ from virtualenvwrapper .user_scripts import PERMISSIONS , make_hook , run_global
12
12
13
13
log = logging .getLogger (__name__ )
14
14
@@ -58,4 +58,19 @@ def post_activate_source(args):
58
58
-a "$VIRTUALENVWRAPPER_PROJECT_CD" = 1 ] && \
59
59
virtualenvwrapper_cd \
60
60
"$(cat \" $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" )"
61
+ if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]; then
62
+ if [ -f "$(cat \" $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" )/.virtualenvwrapper/postactivate" ]; then
63
+ source "$(cat \" $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" )/.virtualenvwrapper/postactivate"
64
+ fi
65
+ fi
66
+ """
67
+
68
+
69
+ def pre_deactivate_source (args ):
70
+ return """
71
+ if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]; then
72
+ if [ -f "$(cat \" $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" )/.virtualenvwrapper/predeactivate" ]; then
73
+ source "$(cat \" $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" )/.virtualenvwrapper/predeactivate"
74
+ fi
75
+ fi
61
76
"""
You can’t perform that action at this time.
0 commit comments