Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ Convenience Commands
(added in v.1.2.4)

Hooks
-----
----------
To run some commands after ``mkvirtualenv`` you can use hooks. First
you need to define ``VIRTUALENVWRAPPER_HOOK_DIR`` variable. If it is
set ``mkvirtualenv`` will run ``postmkvirtualenv.bat`` script from
that directory.
set ``mkvirtualenv`` will run ``postmkvirtualenv.bat`` script and
``workon`` and ``deactivate`` will run ``postactivate.bat`` and
``postdeactivate.bat`` scripts from that directory.

To run some commands after ``workon`` or ``deactivate`` that are
specific to a virtual environment, you can create ``postactivate.bat``
or ``postdeactivate.bat`` scripts in the virtual environment's ``Scripts``
directory.

22 changes: 22 additions & 0 deletions scripts/workon.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ if not "%1"=="" (
)

if defined VIRTUAL_ENV (
SET "VIRTUAL_ENV_POSTDEACTIVATE=%VIRTUAL_ENV%\Scripts\postdeactivate.bat"
call "%VIRTUAL_ENV%\Scripts\deactivate.bat"
if exist "%VIRTUAL_ENV_POSTDEACTIVATE%" (
call "%VIRTUAL_ENV_POSTDEACTIVATE%"
)
SET VIRTUAL_ENV_POSTDEACTIVATE=
if defined VIRTUALENVWRAPPER_HOOK_DIR (
if exist "%VIRTUALENVWRAPPER_HOOK_DIR%\postdeactivate.bat" (
call "%VIRTUALENVWRAPPER_HOOK_DIR%\postdeactivate.bat"
)
)

)


pushd "%WORKON_HOME%" 2>NUL && popd
if errorlevel 1 (
mkdir "%WORKON_HOME%"
Expand Down Expand Up @@ -71,4 +83,14 @@ if exist "%WORKON_HOME%\%VENV%\%VIRTUALENVWRAPPER_PROJECT_FILENAME%" (
)
)

if defined VIRTUALENVWRAPPER_HOOK_DIR (
if exist "%VIRTUALENVWRAPPER_HOOK_DIR%\postactivate.bat" (
call "%VIRTUALENVWRAPPER_HOOK_DIR%\postactivate.bat"
)
)

if exist "%WORKON_HOME%\%VENV%\Scripts\postactivate.bat" (
call "%WORKON_HOME%\%VENV%\Scripts\postactivate.bat"
)

:END