nv_ingest_api.util.imports package#

Submodules#

nv_ingest_api.util.imports.callable_signatures module#

nv_ingest_api.util.imports.callable_signatures.ingest_stage_callable_signature(sig: Signature)[source]#
Validates that a callable has the signature:

(IngestControlMessage, BaseModel) -> IngestControlMessage

Raises:

TypeError – If the signature does not match the expected pattern.

nv_ingest_api.util.imports.dynamic_resolvers module#

nv_ingest_api.util.imports.dynamic_resolvers.resolve_callable_from_path(
callable_path: str,
signature_schema: List[str] | Callable[[Signature], None] | str,
allowed_base_paths: List[str] | None = None,
) Callable[source]#

Import and return a callable from a module path string like ‘module.submodule:callable_name’, and validate its signature using the required signature_schema (callable or path to callable).

Parameters:
  • callable_path (str) – The module path and callable in the format ‘module.sub:callable’.

  • signature_schema (Union[List[str], Callable, str]) –

    Either:
    • A list of parameter names to require.

    • A callable that takes an inspect.Signature and raises on failure.

    • A string path to such a callable (‘module.sub:schema_checker’).

  • allowed_base_paths (Optional[List[str]]) – An optional list of base module paths from which imports are allowed. If provided, both the callable and any signature schema specified by path must reside within one of these paths.

Returns:

The resolved and validated callable.

Return type:

Callable

Raises:
  • ValueError – If the path is not correctly formatted.

  • ImportError – If the module cannot be imported or is not in the allowed paths.

  • AttributeError – If the attribute does not exist in the module.

  • TypeError – If the resolved attribute is not callable or the signature does not match.

nv_ingest_api.util.imports.dynamic_resolvers.resolve_obj_from_path(
path: str,
allowed_base_paths: List[str] | None = None,
) object[source]#

Import and return an object from a string path of the form ‘module.sub:attr’.

To enhance security, this function can restrict imports to a list of allowed base module paths.

Module contents#