Skip to content

cillow.patch

add_patches

Add new patches to be used by all Interpreter instances.

Parameters:

Name Type Description Default
patches PatchProtocol | StreamCapturePatchProtcol

The context manager callables to add

()
Source code in cillow/patch/__init__.py
def add_patches(*patches: PatchProtocol | StreamCapturePatchProtcol) -> None:
    """
    Add new patches to be used by all Interpreter instances.

    Args:
        patches: The context manager callables to add
    """
    for patch in patches:
        if len(signature(patch).parameters) == 0:
            _patches_without_callback.append(patch)  # type: ignore[arg-type]
        else:
            _patches_with_callback.append(patch)  # type: ignore[arg-type]

load_patches

Load the patches inside a context.

Parameters:

Name Type Description Default
on_stream Callable[[Stream | ByteStream], Any]

The callback to capture streaming output.

required
Source code in cillow/patch/__init__.py
@contextmanager
def load_patches(on_stream: Callable[[Stream | ByteStream], Any]) -> Generator[None, None, None]:
    """
    Load the patches inside a context.

    Args:
        on_stream: The callback to capture streaming output.
    """
    with ExitStack() as stack:
        for patch_fn in _patches_without_callback:
            stack.enter_context(patch_fn())
        for _patch_fn in _patches_with_callback:
            stack.enter_context(_patch_fn(on_stream))
        yield

clear_patches

Clear all the added patches.

Source code in cillow/patch/__init__.py
def clear_patches() -> None:
    """Clear all the added patches."""
    _patches_with_callback.clear()
    _patches_without_callback.clear()