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

allow unknown targets #97

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .spellcheck-en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ subdirectory
kickstarts
koji
livemediacreator
untrusted
5 changes: 3 additions & 2 deletions src/otk/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .context import registry as context_registry
from .document import Omnifest
from .help.log import JSONSequenceHandler
from .target import CommonTarget
from .target import registry as target_registry
from .transform import resolve

Expand Down Expand Up @@ -151,8 +152,8 @@ def compile(

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

context = context_registry[kind](ctx)
target = target_registry[kind]()
context = context_registry.get(kind, CommonContext)(ctx)
target = target_registry.get(kind, CommonTarget)()

# This time we resolve with a kind
tree = resolve(context, tree)
Expand Down
12 changes: 11 additions & 1 deletion src/otk/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from typing import Any

from .context import Context, OSBuildContext
from .context import Context, CommonContext, OSBuildContext


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


# NOTE this common target is a bit weird, we probably shouldn't always assume JSON but
# NOTE it makes development a tad easier until we figure out all our targets
class CommonTarget(Target):
def is_valid(self, tree: Any) -> bool:
return True

def as_string(self, context: CommonContext, tree: Any, pretty: bool = True) -> str:
return json.dumps(tree, indent=2 if pretty else None)


class OSBuildTarget(Target):
def is_valid(self, tree: Any) -> bool:
return True
Expand Down
Loading