Skip to content

Commit

Permalink
Fix OmegaConfigLoader __repr__ and missing keys method (#4030)
Browse files Browse the repository at this point in the history
* fix printing

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* add release note

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* typo

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* Return `KeysView` instead of list[str] to please mypy

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* Add a test for coverage

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* linter is not happy about this

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* revert redundant release note

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

---------

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
  • Loading branch information
noklam authored Jul 26, 2024
1 parent fd17607 commit 6609455
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Made [kedro-telemetry](https://github.com/kedro-org/kedro-plugins/tree/main/kedro-telemetry) a core dependency.
* Implemented dataset pretty printing.
* Implemented `DataCatalog` pretty printing.
* Fixed a bug when `OmegaConfigLoader` is printed, there are few missing arguments.
* Fixed a bug when where iterating `OmegaConfigLoader`'s `keys` return empty dictionary.

## Breaking changes to the API

Expand Down
12 changes: 11 additions & 1 deletion kedro/config/omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import mimetypes
import typing
from collections.abc import KeysView
from pathlib import Path
from typing import Any, Callable, Iterable

Expand Down Expand Up @@ -124,6 +125,7 @@ def __init__( # noqa: PLR0913
# Deactivate oc.env built-in resolver for OmegaConf
OmegaConf.clear_resolver("oc.env")
# Register user provided custom resolvers
self._custom_resolvers = custom_resolvers
if custom_resolvers:
self._register_new_resolvers(custom_resolvers)
# Register globals resolver
Expand Down Expand Up @@ -255,9 +257,17 @@ def __getitem__(self, key: str) -> dict[str, Any]: # noqa: PLR0912
def __repr__(self) -> str: # pragma: no cover
return (
f"OmegaConfigLoader(conf_source={self.conf_source}, env={self.env}, "
f"config_patterns={self.config_patterns})"
f"runtime_params={self.runtime_params}, "
f"config_patterns={self.config_patterns}, "
f"base_env={self.base_env}), "
f"default_run_env={self.default_run_env}), "
f"custom_resolvers={self._custom_resolvers}), "
f"merge_strategy={self.merge_strategy})"
)

def keys(self) -> KeysView:
return KeysView(self.config_patterns)

@typing.no_type_check
def load_and_merge_dir_config( # noqa: PLR0913
self,
Expand Down
4 changes: 4 additions & 0 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,3 +1482,7 @@ def test_runtime_params_default_global(self, tmp_path):
conf = OmegaConfigLoader(tmp_path, runtime_params=runtime_params)
# runtime params are resolved correctly in catalog using global default
assert conf["catalog"]["companies"]["type"] == globals_config["dataset"]["type"]

def test_keys_exist(self):
conf = OmegaConfigLoader(conf_source="")
assert list(conf.keys()) == ["catalog", "parameters", "credentials", "globals"]

0 comments on commit 6609455

Please sign in to comment.