modern_urwid.resource.utils

Various utilities for handling resources

Functions

import_module([module_path, file_path])

Import a Python module from a given module or file path

is_class_method(module_registry, unresolved)

resolve_resource(module_registry, unresolved)

Resolve a resource

wrap_callback(callback, *args)

Wrap a callback with the given arguments

modern_urwid.resource.utils.import_module(module_path: str | None = None, file_path: Path | None = None) tuple[str, ModuleType] | None

Import a Python module from a given module or file path

Parameters:
  • module_path (str, optional) – A Python module path (e.g. tests.advanced.extra), defualts to None

  • file_path (str, optional) – A file path to the module, defaults to None

Returns:

A tuple containing the python module and its name, or None if it could not be resolved

Return type:

tuple[str, types.ModuleType] | None

modern_urwid.resource.utils.is_class_method(module_registry: ModuleRegistry, unresolved: UnresolvedResource)
modern_urwid.resource.utils.resolve_resource(module_registry: ModuleRegistry, unresolved: UnresolvedResource, resolve_controllers: bool = True) Any

Resolve a resource

Parameters:
  • module_registry (ModuleRegistry) – The module registry

  • unresolved (UnresolvedResource) – The unresolved resource to evaluate

  • resolve_controllers (bool) – Whether or not to instance controller classes

Returns:

A resolved resource provided by a module

Return type:

Any

modern_urwid.resource.utils.wrap_callback(callback: Callable, *args) Callable

Wrap a callback with the given arguments

Parameters:

callback (Callable) – The callback to wrap

Returns:

Lambda that will call the original callback with the given arguments and any additional arguments at call time

Return type:

Callable