Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 78441e8

Browse files
committed
allow unknown targets
Allow unknown targets by always converting them to JSON and formatting them with a common context. Signed-off-by: Simon de Vlieger <[email protected]>
1 parent 0a96d2c commit 78441e8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/otk/command.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .context import registry as context_registry
1313
from .document import Omnifest
1414
from .help.log import JSONSequenceHandler
15+
from .target import CommonTarget
1516
from .target import registry as target_registry
1617
from .transform import resolve
1718

@@ -151,8 +152,8 @@ def compile(
151152

152153
kind = name.split(".")[0]
153154

154-
context = context_registry[kind](ctx)
155-
target = target_registry[kind]()
155+
context = context_registry.get(kind, CommonContext)(ctx)
156+
target = target_registry.get(kind, CommonTarget)()
156157

157158
# This time we resolve with a kind
158159
tree = resolve(context, tree)

src/otk/target.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from abc import ABC, abstractmethod
44
from typing import Any
55

6-
from .context import Context, OSBuildContext
6+
from .context import Context, CommonContext, OSBuildContext
77

88

99
log = logging.getLogger(__name__)
@@ -17,6 +17,16 @@ def is_valid(self, tree: Any) -> bool: ...
1717
def as_string(self, context: Context, tree: Any, pretty: bool) -> str: ...
1818

1919

20+
# NOTE this common target is a bit weird, we probably shouldn't always assume JSON but
21+
# NOTE it makes development a tad easier until we figure out all our targets
22+
class CommonTarget(Target):
23+
def is_valid(self, tree: Any) -> bool:
24+
return True
25+
26+
def as_string(self, context: CommonContext, tree: Any, pretty: bool = True) -> str:
27+
return json.dumps(tree, indent=2 if pretty else None)
28+
29+
2030
class OSBuildTarget(Target):
2131
def is_valid(self, tree: Any) -> bool:
2232
return True

0 commit comments

Comments
 (0)