verbosemanager¶
verbosemanager is a Python module made for managing verbose output on a complex Python method or function (i.e. one which goes into sub-functions). It allows a process to ‘carry’ its own verbose management through these sub-functions.
If that answers all your questions, see the ‘quick start’ guide below. Else, see the ‘about’ and ‘documentation’ headings below and in the sidebar for further information.
About:
Documentation:
Quick start¶
Ensure you have Python 3.6 or greater.
Install the module using pip:
pip3 install verbosemanager
Import the
VerboseManagerclass and@verbosemanagerdecorator into your python script file:
from verbosemanager import verbosemanager, VerboseManager
Open your favourite process (example process given):
def subprocess():
# subprocess goes here
return something
def process():
# initialisation goes here
# step 1 code goes here
subprocess()
# step 2 code goes here
return something_else
Add
VerboseManagerinstantiation 1 and step functions, the**verbosekwarg to each of your functions, and the@verbosedecoratordecorator:
@verbosedecorator(n_steps=1)
def subprocess(**verbose):
verbose_manager = VerboseManager.instance()
verbose_manager.step("Subprocess step")
# subprocess goes here
return something
@verbosedecorator(n_steps=3)
def process(**verbose):
verbose_manager = VerboseManager.instance()
# initialisation goes here
verbose_manager.step("Step 1")
# step 1 code goes here
subprocess()
verbose_manager.step("Step 2")
# step 2 code goes here
return something_else
(where the @verbosedecorator parameter, n_steps, is the number of step
functions called in the process (including those in subfunctions))
You’re done!
VerboseManagerwill automatically include the subprocess step in your full process (as long as you account for it in the steps parameter of@verbosedecorator) and users will see something like this after your function finishes:
[===============] 100% Complete
Process completed in [time] seconds.
Timings per step:
Initialisation: [time]
Step 1: [time]
|Subprocess step: [time]
Step 2: [time]
More flexibility is available by directly coding in start and stop
functions for your verbose process, but the @verbosedecorator decorator is
a shortcut to access the management functions. See the documentation for
details on directly using them.
- 1
the instantiation functions are needed so the functions can access the ``VerboseManager`` class; Python scoping makes this unavoidable, sadly.