maxent_grpo.utils.imports

Shared helpers for optional and required dependency imports.

Functions

cached_import(module_name)

Import a module with caching to avoid repeated lookups.

optional_import(module_name)

Import a module if available without bubbling up ImportError.

require_dependency(module_name, context_hint)

Import a dependency or raise a helpful error when it is missing.

maxent_grpo.utils.imports.cached_import(module_name)[source]

Import a module with caching to avoid repeated lookups.

Parameters:

module_name (str) – Fully qualified module path to import.

Returns:

Imported module object, cached for subsequent calls.

Raises:

ImportError – Propagated if the module cannot be imported.

Return type:

ModuleType

maxent_grpo.utils.imports.optional_import(module_name)[source]

Import a module if available without bubbling up ImportError.

This deliberately skips the cached importer so tests and call sites that monkeypatch sys.modules see their changes reflected immediately.

Parameters:

module_name (str) – Fully qualified module path to import.

Returns:

Imported module, or None when the module is missing.

Return type:

ModuleType | None

maxent_grpo.utils.imports.require_dependency(module_name, context_hint)[source]

Import a dependency or raise a helpful error when it is missing.

Parameters:
  • module_name (str) – Fully qualified module path to import.

  • context_hint (str) – Human-friendly error message describing the caller context.

Returns:

Imported module, if available.

Raises:

ImportError – Wrapped with context_hint when the dependency is absent.

Return type:

ModuleType