From 57a75399a26b75963de159667e591f2ebd3ca8be Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 3 Jul 2026 17:10:02 +0200 Subject: [PATCH] load_yaml: Rename include directive to jw.include The include directive was previously triggered by a bare "include" key in YAML files. This could collide with user-defined keys. Rename it to "jw.include" so that: jw.include: file.yaml jw.include: - file1.yaml - file2.yaml is used instead of just "include:". This follows the convention established by "jw.link" for link expansion markers. Signed-off-by: Jan Lindemann --- src/python/jw/util/load_yaml.py | 4 +-- test/unit/python/jw/util/load_yaml/test.py | 30 +++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/python/jw/util/load_yaml.py b/src/python/jw/util/load_yaml.py index 6750a9b..00efa4a 100644 --- a/src/python/jw/util/load_yaml.py +++ b/src/python/jw/util/load_yaml.py @@ -72,8 +72,8 @@ def _load_yaml(path: str | Path, optional: bool, seen: set[Path]) -> dict[str, A if optional: return {} raise - includes = _normalize_include_specs(ret.get('include', []), path.parent) - ret.pop('include', None) + includes = _normalize_include_specs(ret.get('jw.include', []), path.parent) + ret.pop('jw.include', None) included_all: dict[str, Any] = {} for include in includes: included_next = _load_yaml(include[1], optional = include[0], seen = seen) diff --git a/test/unit/python/jw/util/load_yaml/test.py b/test/unit/python/jw/util/load_yaml/test.py index 3a50c25..c145cdc 100644 --- a/test/unit/python/jw/util/load_yaml/test.py +++ b/test/unit/python/jw/util/load_yaml/test.py @@ -139,7 +139,7 @@ class TestIncludeDirective: base = temp_dir( [ ('base.yaml', 'shared: from_base\n'), - ('main.yaml', 'include: base.yaml\ncurrent: here\n'), + ('main.yaml', 'jw.include: base.yaml\ncurrent: here\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -151,7 +151,7 @@ class TestIncludeDirective: [ ('a.yaml', 'from_a: 1\nshared: a\n'), ('b.yaml', 'from_b: 2\nshared: b\n'), - ('main.yaml', 'include:\n - a.yaml\n - b.yaml\nlocal: yes\n'), + ('main.yaml', 'jw.include:\n - a.yaml\n - b.yaml\nlocal: yes\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -164,7 +164,7 @@ class TestIncludeDirective: def test_optional_include(self, temp_dir: Callable) -> None: base = temp_dir( [ - ('main.yaml', 'include:\n - "- nonexist.yaml"\nok: true\n'), + ('main.yaml', 'jw.include:\n - "- nonexist.yaml"\nok: true\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -175,7 +175,13 @@ class TestIncludeDirective: [ ('base.yaml', 'config:\n db:\n host: localhost\n port: 5432\n'), ('override.yaml', 'config:\n db:\n port: 3306\n name: mydb\n'), - ('main.yaml', 'include:\n - override.yaml\nconfig:\n cache: true\n'), + ( + 'main.yaml', + 'jw.include:\n' + ' - override.yaml\n' + 'config:\n' + ' cache: true\n' + ), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -187,8 +193,8 @@ class TestIncludeDirective: base = temp_dir( [ ('level1.yaml', 'from: level1\n'), - ('level2.yaml', 'include: level1.yaml\nfrom: level2\n'), - ('main.yaml', 'include: level2.yaml\n'), + ('level2.yaml', 'jw.include: level1.yaml\nfrom: level2\n'), + ('main.yaml', 'jw.include: level2.yaml\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -197,8 +203,8 @@ class TestIncludeDirective: def test_include_circular_detect(self, temp_dir: Callable) -> None: base = temp_dir( [ - ('a.yaml', 'include: b.yaml\n'), - ('b.yaml', 'include: a.yaml\n'), + ('a.yaml', 'jw.include: b.yaml\n'), + ('b.yaml', 'jw.include: a.yaml\n'), ] ) with pytest.raises(ValueError, match = 'Cyclic YAML include'): @@ -208,7 +214,7 @@ class TestIncludeDirective: base = temp_dir( [ ('sub/inner.yaml', 'secret: found\n'), - ('main.yaml', 'include: sub/inner.yaml\n'), + ('main.yaml', 'jw.include: sub/inner.yaml\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -526,7 +532,7 @@ class TestIncludePlusLinks: base = temp_dir( [ ('base.yaml', 'shared: from_include\n'), - ('main.yaml', 'include: base.yaml\nlink:\n jw.link: shared\n'), + ('main.yaml', 'jw.include: base.yaml\nlink:\n jw.link: shared\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -537,7 +543,7 @@ class TestIncludePlusLinks: base = temp_dir( [ ('base.yaml', 'target: included\ndecorator:\n jw.link: target\n'), - ('main.yaml', 'include: base.yaml\nlocal: here\n'), + ('main.yaml', 'jw.include: base.yaml\nlocal: here\n'), ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') @@ -550,7 +556,7 @@ class TestIncludePlusLinks: ('base.yaml', 'base_val: ok\n'), ( 'main.yaml', - 'include: base.yaml\nlocal:\n link:\n jw.link: ..base_val\n' + 'jw.include: base.yaml\nlocal:\n link:\n jw.link: ..base_val\n' ), ] )