Note
This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.
brainprep.decorators.PythonWrapperHook¶
- class brainprep.decorators.PythonWrapperHook[source]¶
Bases:
HookPerform Python wrapper-specific preprocessing and output validation.
This hook provides two core features:
Automatically injects a dryrun argument.
Recursively validates all generated output files.
- Raises:
- ValueError
If invalid wrapper type is specified.
Examples
>>> from brainprep.decorators import step, PythonWrapperHook >>> from brainprep.config import Config
>>> @step( ... hooks=[PythonWrapperHook()] ... ) ... def ls_command(my_dir, dryrun=False): ... if dryrun: ... return None ... return os.listdir(my_dir)
>>> with Config(dryrun=True): ... ls_command("/tmp")
- after_call(outputs)[source]¶
Transform and inspect outputs after the function call.
This method inspects the output returned by the decorated function, recursively validates each file path, and normalizes the return type:
Noneis returned unchanged.A single-file output is returned as a
File.Multiple files are returned as a
tuple[File].
- Parameters:
- outputsFile | tuple[File] | None
The output file or tuple of files returned by the decorated function, or
Noneif no output was produced.
- Returns:
- outputsFile | tuple[File] | None
The validated output.
- before_call(func, inputs)[source]¶
Transform and inspect inputs before the function call.
- Parameters:
- funcCallable
The function to be decorated.
- inputsdict[str, Any]
Positional and keyword arguments passed to func.
- Returns:
- inputsdict[str, Any]
Positional and keyword arguments passed to func with the dryrun parameter set.
- Raises:
- ValueError
If the decorated function have no dryrun keyword argument.