|
| 1 | +.. _hooks-scripts: |
| 2 | + |
| 3 | +Per-User Hook Scripts |
| 4 | +===================== |
| 5 | + |
| 6 | +The end-user customization scripts are either *sourced* (allowing them |
| 7 | +to modify your shell environment) or *run* as an external program at |
| 8 | +the appropriate trigger time. |
| 9 | + |
| 10 | +.. _hooks-scripts-initialize: |
| 11 | + |
| 12 | +initialize |
| 13 | +---------- |
| 14 | + |
| 15 | + :Global/Local: global |
| 16 | + :Argument(s): None |
| 17 | + :Sourced/Run: run |
| 18 | + |
| 19 | +``$WORKON_HOME/initialize`` is sourced when ``virtualenvwrapper.sh`` |
| 20 | +is loaded into your environment. Use it to adjust global settings |
| 21 | +when virtualenvwrapper is enabled. |
| 22 | + |
| 23 | +.. _hooks-scripts-premkvirtualenv: |
| 24 | + |
| 25 | +premkvirtualenv |
| 26 | +--------------- |
| 27 | + |
| 28 | + :Global/Local: global |
| 29 | + :Argument(s): name of new environment |
| 30 | + :Sourced/Run: run |
| 31 | + |
| 32 | +``$WORKON_HOME/premkvirtualenv`` is run as an external program after |
| 33 | +the virtual environment is created but before the current environment |
| 34 | +is switched to point to the new env. The current working directory for |
| 35 | +the script is ``$WORKON_HOME`` and the name of the new environment is |
| 36 | +passed as an argument to the script. |
| 37 | + |
| 38 | +.. _hooks-scripts-postmkvirtualenv: |
| 39 | + |
| 40 | +postmkvirtualenv |
| 41 | +---------------- |
| 42 | + |
| 43 | + :Global/Local: global |
| 44 | + :Argument(s): none |
| 45 | + :Sourced/Run: sourced |
| 46 | + |
| 47 | +``$WORKON_HOME/postmkvirtualenv`` is sourced after the new environment |
| 48 | +is created and activated. |
| 49 | + |
| 50 | +.. _hooks-scripts-preactivate: |
| 51 | + |
| 52 | +preactivate |
| 53 | +----------- |
| 54 | + |
| 55 | + :Global/Local: global, local |
| 56 | + :Argument(s): environment name |
| 57 | + :Sourced/Run: run |
| 58 | + |
| 59 | +The global ``$WORKON_HOME/preactivate`` script is run before the new |
| 60 | +environment is enabled. The environment name is passed as the first |
| 61 | +argument. |
| 62 | + |
| 63 | +The local ``$VIRTUAL_ENV/bin/preactivate`` hook is run before the new |
| 64 | +environment is enabled. The environment name is passed as the first |
| 65 | +argument. |
| 66 | + |
| 67 | +.. _hooks-scripts-postactivate: |
| 68 | + |
| 69 | +postactivate |
| 70 | +------------ |
| 71 | + |
| 72 | + :Global/Local: global, local |
| 73 | + :Argument(s): none |
| 74 | + :Sourced/Run: sourced |
| 75 | + |
| 76 | +The global ``$WORKON_HOME/postactivate`` script is sourced after the |
| 77 | +new environment is enabled. ``$VIRTUAL_ENV`` refers to the new |
| 78 | +environment at the time the script runs. |
| 79 | + |
| 80 | +This example script adds a space between the virtual environment name |
| 81 | +and your old PS1 by making use of ``_OLD_VIRTUAL_PS1``. |
| 82 | + |
| 83 | +:: |
| 84 | + |
| 85 | + PS1="(`basename \"$VIRTUAL_ENV\"`) $_OLD_VIRTUAL_PS1" |
| 86 | + |
| 87 | +The local ``$VIRTUAL_ENV/bin/postactivate`` script is sourced after |
| 88 | +the new environment is enabled. ``$VIRTUAL_ENV`` refers to the new |
| 89 | +environment at the time the script runs. |
| 90 | + |
| 91 | +This example script for the PyMOTW environment changes the current |
| 92 | +working directory and the PATH variable to refer to the source tree |
| 93 | +containing the PyMOTW source. |
| 94 | + |
| 95 | +:: |
| 96 | + |
| 97 | + pymotw_root=/Users/dhellmann/Documents/PyMOTW |
| 98 | + cd $pymotw_root |
| 99 | + PATH=$pymotw_root/bin:$PATH |
| 100 | + |
| 101 | +.. _hooks-scripts-predeactivate: |
| 102 | + |
| 103 | +predeactivate |
| 104 | +------------- |
| 105 | + |
| 106 | + :Global/Local: local, global |
| 107 | + :Argument(s): none |
| 108 | + :Sourced/Run: sourced |
| 109 | + |
| 110 | +The local ``$VIRTUAL_ENV/bin/predeactivate`` script is sourced before the |
| 111 | +current environment is deactivated, and can be used to disable or |
| 112 | +clear settings in your environment. ``$VIRTUAL_ENV`` refers to the old |
| 113 | +environment at the time the script runs. |
| 114 | + |
| 115 | +The global ``$WORKON_HOME/predeactivate`` script is sourced before the |
| 116 | +current environment is deactivated. ``$VIRTUAL_ENV`` refers to the |
| 117 | +old environment at the time the script runs. |
| 118 | + |
| 119 | +.. _hooks-scripts-postdeactivate: |
| 120 | + |
| 121 | +postdeactivate |
| 122 | +-------------- |
| 123 | + |
| 124 | + :Global/Local: local, global |
| 125 | + :Argument(s): none |
| 126 | + :Sourced/Run: sourced |
| 127 | + |
| 128 | +The ``$VIRTUAL_ENV/bin/postdeactivate`` script is sourced after the |
| 129 | +current environment is deactivated, and can be used to disable or |
| 130 | +clear settings in your environment. The path to the environment just |
| 131 | +deactivated is available in ``$VIRTUALENVWRAPPER_LAST_VIRTUALENV``. |
| 132 | + |
| 133 | +.. _hooks-scripts-prermvirtualenv: |
| 134 | + |
| 135 | +prermvirtualenv |
| 136 | +--------------- |
| 137 | + |
| 138 | + :Global/Local: global |
| 139 | + :Argument(s): environment name |
| 140 | + :Sourced/Run: run |
| 141 | + |
| 142 | +The ``$WORKON_HOME/prermvirtualenv`` script is run as an external |
| 143 | +program before the environment is removed. The full path to the |
| 144 | +environment directory is passed as an argument to the script. |
| 145 | + |
| 146 | +.. _hooks-scripts-postrmvirtualenv: |
| 147 | + |
| 148 | +postrmvirtualenv |
| 149 | +---------------- |
| 150 | + |
| 151 | + :Global/Local: global |
| 152 | + :Argument(s): environment name |
| 153 | + :Sourced/Run: run |
| 154 | + |
| 155 | +The ``$WORKON_HOME/postrmvirtualenv`` script is run as an external |
| 156 | +program after the environment is removed. The full path to the |
| 157 | +environment directory is passed as an argument to the script. |
0 commit comments