Skip to content

setup

setup

Shared execution setup — pure functions with no UI dependencies.

Consolidates the component creation logic that was duplicated between cli/commands/_shared.py and daemon/job_service.py. Both paths now call these functions:

  • CLI wraps them with Rich console output for verbosity.
  • Daemon calls them directly (no console).

This eliminates the "mirrors _shared.py" comments in job_service.py and ensures that adding a new backend type only requires updating one place.

Classes

Functions:

setup_learning

setup_learning(config, *, global_learning_store_override=None)

Setup outcome store and global learning store if learning is enabled.

Parameters:

Name Type Description Default
config JobConfig

Job configuration with learning settings.

required
global_learning_store_override GlobalLearningStore | None

If provided, use this store instead of the module-level singleton. The daemon injects its shared LearningHub store here to avoid opening a second SQLite connection.

None

Returns:

Type Description
tuple[OutcomeStore | None, GlobalLearningStore | None]

Tuple of (outcome_store, global_learning_store), either may be None.

Source code in src/marianne/execution/setup.py
def setup_learning(
    config: JobConfig,
    *,
    global_learning_store_override: GlobalLearningStore | None = None,
) -> tuple[OutcomeStore | None, GlobalLearningStore | None]:
    """Setup outcome store and global learning store if learning is enabled.

    Args:
        config: Job configuration with learning settings.
        global_learning_store_override: If provided, use this store instead
            of the module-level singleton.  The daemon injects its shared
            LearningHub store here to avoid opening a second SQLite connection.

    Returns:
        Tuple of (outcome_store, global_learning_store), either may be None.
    """
    if not config.learning.enabled:
        return None, None

    from marianne.learning.outcomes import JsonOutcomeStore

    outcome_store: OutcomeStore | None = None
    outcome_store_path = config.get_outcome_store_path()
    if config.learning.outcome_store_type == "json":
        outcome_store = JsonOutcomeStore(outcome_store_path)

    # Prefer injected store (from daemon LearningHub) over the
    # module-level singleton.  This avoids opening a second
    # SQLite connection when the daemon already owns one.
    if global_learning_store_override is not None:
        global_learning_store = global_learning_store_override
    else:
        from marianne.learning.global_store import get_global_store

        global_learning_store = get_global_store()

    return outcome_store, global_learning_store

setup_notifications

setup_notifications(config)

Setup notification manager from config.

Parameters:

Name Type Description Default
config JobConfig

Job configuration with notification settings.

required

Returns:

Type Description
NotificationManager | None

NotificationManager if notifications configured, else None.

Source code in src/marianne/execution/setup.py
def setup_notifications(config: JobConfig) -> NotificationManager | None:
    """Setup notification manager from config.

    Args:
        config: Job configuration with notification settings.

    Returns:
        NotificationManager if notifications configured, else None.
    """
    if not config.notifications:
        return None

    from marianne.notifications import NotificationManager
    from marianne.notifications.factory import create_notifiers_from_config

    notifiers = create_notifiers_from_config(config.notifications)
    if not notifiers:
        return None

    return NotificationManager(notifiers)

create_state_backend

create_state_backend(workspace, backend_type='json')

Create state persistence backend.

Parameters:

Name Type Description Default
workspace Path

Workspace directory for state files.

required
backend_type str

"json" or "sqlite".

'json'

Returns:

Type Description
StateBackend

Configured StateBackend instance.

Source code in src/marianne/execution/setup.py
def create_state_backend(
    workspace: Path,
    backend_type: str = "json",
) -> StateBackend:
    """Create state persistence backend.

    Args:
        workspace: Workspace directory for state files.
        backend_type: "json" or "sqlite".

    Returns:
        Configured StateBackend instance.
    """
    from marianne.state import JsonStateBackend, SQLiteStateBackend

    if backend_type == "sqlite":
        return SQLiteStateBackend(workspace / STATE_DB_FILENAME)
    else:
        return JsonStateBackend(workspace)