diff --git a/modules/utils.py b/modules/utils.py index e32d6ae..f19bc63 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -364,10 +364,28 @@ def virtualenv_source(): @_contextmanager def virtualenv(): """ - helper method to set the virtual environment for the following commands + Context manager for setting the virtual environment for commands. - uses python yield command + This helper method sets up the virtual environment specified in the + configuration before executing any commands within its context. It uses + the Python context manager pattern with the `yield` keyword to + temporarily modify the environment for the duration of the with-block. + The virtual environment is specified by the name in + `configuration.virtualenv.name` and is activated using the `workon` + command. + + Note: + - This method relies on the Fabric library's `prefix` context manager + and assumes the use of virtualenvwrapper or a similar tool for + managing virtual environments. + - The method expects `configuration.virtualenv.name` to be properly + set in `env.config`. + + Example Usage: + with virtualenv(): + run("python manage.py migrate") """ + configuration = env.config with virtualenv_source(): with prefix("workon %s" % configuration.virtualenv.name):