Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove omegaconf as a dependencies of KedroContext #4405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions kedro/framework/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from warnings import warn

from attrs import define, field
from omegaconf import OmegaConf

from kedro.config import AbstractConfigLoader, MissingConfigException
from kedro.framework.project import settings
Expand Down Expand Up @@ -144,6 +143,21 @@ def _expand_full_path(project_path: str | Path) -> Path:
return Path(project_path).expanduser().resolve()


def _update_nested_dict(old_dict: dict[Any, Any], new_dict: dict[Any, Any]) -> None:
"""Update a nested dict with values of new_dict.
Args:
old_dict: dict to be updated
new_dict: dict to use for updating old_dict
"""
for key, value in new_dict.items():
if key not in old_dict:
old_dict[key] = value
elif isinstance(old_dict[key], dict) and isinstance(value, dict):
_update_nested_dict(old_dict[key], value)
else:
old_dict[key] = value


@define(slots=False) # Enable setting new attributes to `KedroContext`
class KedroContext:
"""``KedroContext`` is the base class which holds the configuration and
Expand Down Expand Up @@ -202,12 +216,8 @@ def params(self) -> dict[str, Any]:
except MissingConfigException as exc:
warn(f"Parameters not found in your Kedro project config.\n{exc!s}")
params = {}

if self._extra_params:
# Merge nested structures
params = OmegaConf.merge(params, self._extra_params)

return OmegaConf.to_container(params) if OmegaConf.is_config(params) else params # type: ignore[return-value]
_update_nested_dict(params, self._extra_params or {})
return params

def _get_catalog(
self,
Expand Down
Loading