nv_ingest_api.util.imports package#
Submodules#
nv_ingest_api.util.imports.callable_signatures module#
- nv_ingest_api.util.imports.callable_signatures.ingest_callable_signature(sig: Signature)[source]#
- Validates that a callable has the signature:
(IngestControlMessage) -> IngestControlMessage
Also allows for generic (*args, **kwargs) signatures for flexibility with class constructors.
- Raises:
TypeError – If the signature does not match the expected pattern.
- nv_ingest_api.util.imports.callable_signatures.ingest_stage_callable_signature(sig: Signature)[source]#
- Validates that a callable has the signature:
(IngestControlMessage, BaseModel) -> IngestControlMessage
Also allows for generic (*args, **kwargs) signatures for flexibility with class constructors.
- 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_actor_class_from_path(
- path: str,
- expected_base_class: type,
- allowed_base_paths: List[str] | None = None,
Resolves an actor class from a path and validates that it is a class that inherits from the expected base class. This function correctly handles decorated Ray actors by inspecting their original class.
- Parameters:
path (str) – The full import path to the actor class.
expected_base_class (type) – The base class that the resolved class must inherit from.
allowed_base_paths (Optional[List[str]]) – An optional list of base module paths from which imports are allowed.
- Returns:
The resolved actor class (or Ray actor factory).
- Return type:
type
- 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,
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,
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.