Skip to content

Commit

Permalink
otk: implement simple --preload
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Oct 31, 2024
1 parent 9d284fe commit 553115f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/otk/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def parser_create() -> argparse.ArgumentParser:
default=None,
help="Target to output, required if more than one target exists in an omnifest.",
)
parser_compile.add_argument(
"-p",
"--preload",
default=None,
help="Preload the given otk file before processing the input",
)

parser_validate = subparsers.add_parser("validate", help="Validate an omnifest.")
parser_validate.add_argument(
Expand Down
6 changes: 5 additions & 1 deletion src/otk/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def __init__(self, path: pathlib.Path, target: str = "", *, warn_duplicated_defs
raise OTKError("only target osbuild supported right now")
self._osbuild_ctx = OSBuildContext(self._ctx)
state = State()
tree = process_include(self._ctx, state, path)
if not isinstance(path, list):
path = [path]
tree = {}
for p in path:
tree.update(process_include(self._ctx, state, p))
# XXX: review this code, the idea is to find top-level keys that
# have no targets but that of course only works if there are
# no targets in the resolving. this means we are currently forced
Expand Down
36 changes: 36 additions & 0 deletions test/test_preload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import os
import textwrap

import pytest

from otk.command import run


def test_otk_preload_works(tmp_path, caplog):
preload_otk = tmp_path / "preload.yaml"
preload_otk.write_text(textwrap.dedent("""
otk.target.osbuild:
otk.define:
user:
modifications:
language: nl_NL.UTF-8
"""))

test_otk = tmp_path / "foo.yaml"
test_otk.write_text(textwrap.dedent("""
otk.version: 1
otk.target.osbuild:
otk.define:
default:
modifications:
language: en_US.UTF-8
modifications:
otk.op.join:
values:
- ${default.modifications}
- ${user.modifications}
"""))
result_otk = tmp_path / "output.yaml"
run(["compile", os.fspath(test_otk), "-o", result_otk.as_posix()])
assert "xx" == result_otk.read_text()

0 comments on commit 553115f

Please sign in to comment.