Skip to content

Commit f5a6579

Browse files
aseemsangalaymerelchtlrcouto
authored
feat(config): Make hidden file inclusion configurable in OmegaConfigLoader (#5006)
* feat(config): Make hidden file inclusion configurable in OmegaConfigLoader Signed-off-by: aseemsangalay <[email protected]> * Add ignore_hidden parameter to docstring Signed-off-by: Laura Couto <[email protected]> * Add new parameter to docs Signed-off-by: Laura Couto <[email protected]> * Vale suggestion Signed-off-by: Laura Couto <[email protected]> * Update docs/configure/advanced_configuration.md Signed-off-by: Merel Theisen <[email protected]> * Update RELEASE.md Signed-off-by: Laura Couto <[email protected]> * Simplify release note Signed-off-by: Laura Couto <[email protected]> --------- Signed-off-by: aseemsangalay <[email protected]> Signed-off-by: Laura Couto <[email protected]> Signed-off-by: Merel Theisen <[email protected]> Co-authored-by: Merel Theisen <[email protected]> Co-authored-by: L. R. Couto <[email protected]> Co-authored-by: Laura Couto <[email protected]>
1 parent 491c822 commit f5a6579

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

RELEASE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Upcoming Release
2+
23
## Major features and improvements
4+
* Added the `ignore_hidden` parameter to the `OmegaConfigLoader`.
5+
36
## Bug fixes and other changes
7+
48
## Community contributions
9+
Many thanks to the following Kedroids for contributing PRs to this release:
10+
* [Aseem Sangalay](https://github.com/aseemsangalay)
511

612
# Release 1.0.0
713
## Major features and improvements

docs/configure/advanced_configuration.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,15 @@ If you run it from the same directory where `parameters.yml` placed it gives the
413413
```console
414414
{'polars_float64': Float64, 'today': datetime.date(2023, 11, 23)}
415415
```
416+
417+
### How to ignore hidden files and directories with `OmegaConfigLoader`
418+
419+
The `OmegaConfigLoader` provides an option to ignore hidden files and directories (those starting with a dot, for example, `.hidden_file` or `.hidden_folder`) when loading configuration files. This behaviour is controlled by the `ignore_hidden` parameter, which is set to `True` by default.
420+
421+
If you want to include hidden files and directories in your configuration loading process, you can set `ignore_hidden` to False when instantiating the `OmegaConfigLoader`:
422+
423+
```py
424+
from kedro.config import OmegaConfigLoader
425+
426+
conf_loader = OmegaConfigLoader(conf_source="conf", ignore_hidden=False)
427+
```

kedro/config/omegaconf_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__( # noqa: PLR0913
9999
default_run_env: str | None = None,
100100
custom_resolvers: dict[str, Callable] | None = None,
101101
merge_strategy: dict[str, str] | None = None,
102+
ignore_hidden: bool = True,
102103
):
103104
if isinstance(conf_source, Path):
104105
conf_source = str(conf_source)
@@ -126,7 +127,10 @@ def __init__( # noqa: PLR0913
126127
see here: https://omegaconf.readthedocs.io/en/2.3_branch/custom_resolvers.html#custom-resolvers
127128
merge_strategy: A dictionary that specifies the merging strategy for each configuration type.
128129
The accepted merging strategies are `soft` and `destructive`. Defaults to `destructive`.
130+
ignore_hidden: A boolean flag that determines whether hidden files and directories should be
131+
ignored when loading configuration files. If True, ignore hidden files and files in hidden directories.
129132
"""
133+
self.ignore_hidden = ignore_hidden
130134
self.base_env = base_env or ""
131135
self.default_run_env = default_run_env or ""
132136
self.merge_strategy = merge_strategy or {}
@@ -332,7 +336,7 @@ def load_and_merge_dir_config(
332336
paths = []
333337
for pattern in patterns:
334338
for each in self._fs.glob(Path(f"{conf_path!s}/{pattern}").as_posix()):
335-
if not self._is_hidden(each):
339+
if not self.ignore_hidden or not self._is_hidden(each):
336340
paths.append(Path(each))
337341

338342
deduplicated_paths = set(paths)

tests/config/test_omegaconf_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,3 +1684,27 @@ def test_remote_dir_not_exists_exception(self, tmp_path, mocker):
16841684
match="Given configuration path either does not exist or is not a valid directory.*Error: No such file or bucket",
16851685
):
16861686
conf["catalog"]
1687+
1688+
def test_hidden_files_ignored_by_default(self, tmp_path):
1689+
base_dir = tmp_path / "base"
1690+
base_dir.mkdir()
1691+
(base_dir / ".hidden.yml").write_text("foo: bar")
1692+
1693+
config_loader = OmegaConfigLoader(conf_source=str(tmp_path))
1694+
config_loader.config_patterns = {"catalog": ["**/*.yml"]}
1695+
1696+
result = config_loader["catalog"]
1697+
assert "foo" not in result
1698+
1699+
def test_hidden_files_included_when_not_ignored(self, tmp_path):
1700+
base_dir = tmp_path / "base"
1701+
base_dir.mkdir()
1702+
(base_dir / ".hidden.yml").write_text("foo: bar")
1703+
1704+
config_loader = OmegaConfigLoader(
1705+
conf_source=str(tmp_path), ignore_hidden=False
1706+
)
1707+
config_loader.config_patterns = {"catalog": ["**/*.yml"]}
1708+
1709+
result = config_loader["catalog"]
1710+
assert "foo" in result

0 commit comments

Comments
 (0)