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 11CHANGES
22=======
33
4+ Next
5+ ----
6+
7+ * Look for `./.virtualenvwrapper/postactivate ` and
8+ `./.virtualenvwrapper/predeactivate ` hook scripts.
9+
4106.0.0.0a5
511---------
612
Original file line number Diff line number Diff line change @@ -31,6 +31,22 @@ site, combine the :ref:`templates-bitbucket` and
3131
3232 $ mkproject -t bitbucket -t django my_site
3333
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+
3450.. seealso ::
3551
3652 * :ref: `extensions-templates `
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ project = "virtualenvwrapper.project:post_activate_source"
9393user_scripts = " virtualenvwrapper.user_scripts:post_activate_source"
9494
9595[project .entry-points ."virtualenvwrapper .pre_deactivate_source" ]
96+ project = " virtualenvwrapper.project:pre_deactivate_source"
9697user_scripts = " virtualenvwrapper.user_scripts:pre_deactivate_source"
9798
9899[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() {
5252 PROJECT_HOME=" $old_home "
5353}
5454
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+
5575. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ setenv =
2323deps = .[linter]
2424commands = flake8 virtualenvwrapper docs/source/conf.py
2525
26+ [flake8]
27+ max-line-length = 200
28+
2629[testenv:zsh]
2730setenv =
2831 USING_TOX = 1
Original file line number Diff line number Diff line change 88import logging
99import os
1010
11- from virtualenvwrapper .user_scripts import make_hook , run_global , PERMISSIONS
11+ from virtualenvwrapper .user_scripts import PERMISSIONS , make_hook , run_global
1212
1313log = logging .getLogger (__name__ )
1414
@@ -58,4 +58,19 @@ def post_activate_source(args):
5858 -a "$VIRTUALENVWRAPPER_PROJECT_CD" = 1 ] && \
5959 virtualenvwrapper_cd \
6060 "$(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
6176"""
You can’t perform that action at this time.
0 commit comments