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

Fix OmegaConfigLoader __repr__ and missing keys method #4030

Merged
merged 8 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 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.

Check warning on line 14 in RELEASE.md

View workflow job for this annotation

GitHub Actions / vale

[vale] RELEASE.md#L14

[Kedro.weaselwords] 'few' is a weasel word!
Raw output
{"message": "[Kedro.weaselwords] 'few' is a weasel word!", "location": {"path": "RELEASE.md", "range": {"start": {"line": 14, "column": 62}}}, "severity": "WARNING"}
* Fixed a bug when where iterating `OmegaConfigLoader`'s `keys` return empty dictionary.

## Breaking changes to the API

Expand Down Expand Up @@ -77,6 +79,7 @@
* Fixed error handling message for malformed yaml/json files in OmegaConfigLoader.
* Fixed a bug in `node`-creation allowing self-dependencies when using transcoding, that is datasets named like `name@format`.
* Improved error message when passing wrong value to node.
* Fixed a bug when `OmegaConfigLoader` is printed, there is a few arguments missing.

Check warning on line 82 in RELEASE.md

View workflow job for this annotation

GitHub Actions / vale

[vale] RELEASE.md#L82

[Kedro.weaselwords] 'few' is a weasel word!
Raw output
{"message": "[Kedro.weaselwords] 'few' is a weasel word!", "location": {"path": "RELEASE.md", "range": {"start": {"line": 82, "column": 63}}}, "severity": "WARNING"}
noklam marked this conversation as resolved.
Show resolved Hide resolved

## Breaking changes to the API
* Methods `_is_project` and `_find_kedro_project` have been moved to `kedro.utils`. We recommend not using private methods in your code, but if you do, please update your code to use the new location.
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"]