Skip to content

WorkspacesConfig

kedro_azureml_pipeline.config.WorkspacesConfig

Bases: RootModel[dict[str, WorkspaceConfig]]

Named workspaces with a mandatory __default__ entry.

Jobs reference a workspace by name; resolve falls back to __default__ when name is None.

See Also

WorkspaceConfig : Single workspace identity. KedroAzureMLConfig : Top-level plugin configuration.

Source Code

Show/Hide source
class WorkspacesConfig(RootModel[dict[str, WorkspaceConfig]]):
    """Named workspaces with a mandatory ``__default__`` entry.

    Jobs reference a workspace by name; ``resolve`` falls back to
    ``__default__`` when *name* is ``None``.

    See Also
    --------
    [WorkspaceConfig][kedro_azureml_pipeline.config.WorkspaceConfig] : Single workspace identity.
    [KedroAzureMLConfig][kedro_azureml_pipeline.config.KedroAzureMLConfig] : Top-level plugin configuration.
    """

    @model_validator(mode="after")
    def _validate_default_key(self) -> "WorkspacesConfig":
        """Ensure a ``__default__`` workspace is present.

        Returns
        -------
        WorkspacesConfig
            The validated instance.

        Raises
        ------
        ValueError
            If the ``__default__`` key is missing.
        """
        if "__default__" not in self.root:
            raise ValueError("WorkspacesConfig must contain a '__default__' key")
        return self

    def resolve(self, name: str | None = None) -> WorkspaceConfig:
        """Return the workspace for *name*, falling back to ``__default__``.

        Parameters
        ----------
        name : str or None
            Workspace name to look up. Falls back to ``__default__``
            when ``None``.

        Returns
        -------
        WorkspaceConfig
            The resolved workspace configuration.

        Raises
        ------
        KeyError
            If *name* is given but not found in the mapping.
        """
        if name and name in self.root:
            return self.root[name]
        if name and name not in self.root:
            raise KeyError(f"Workspace '{name}' not found. Available: {', '.join(sorted(self.root.keys()))}")
        return self.root["__default__"]

Methods

resolve(name=None)

Return the workspace for name, falling back to __default__.

Parameters
Name Type Description Default
name str or None

Workspace name to look up. Falls back to __default__ when None.

None
Returns
Type Description
WorkspaceConfig

The resolved workspace configuration.

Raises
Type Description
KeyError

If name is given but not found in the mapping.

Source Code
Show/Hide source
def resolve(self, name: str | None = None) -> WorkspaceConfig:
    """Return the workspace for *name*, falling back to ``__default__``.

    Parameters
    ----------
    name : str or None
        Workspace name to look up. Falls back to ``__default__``
        when ``None``.

    Returns
    -------
    WorkspaceConfig
        The resolved workspace configuration.

    Raises
    ------
    KeyError
        If *name* is given but not found in the mapping.
    """
    if name and name in self.root:
        return self.root[name]
    if name and name not in self.root:
        raise KeyError(f"Workspace '{name}' not found. Available: {', '.join(sorted(self.root.keys()))}")
    return self.root["__default__"]