Skip to content

Commit

Permalink
Enable eager evaluation of yaml constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
giffels committed May 24, 2024
1 parent b4c2312 commit d9e781a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tardis/configuration/utilities.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from cobald.daemon.plugins import YAMLTagSettings
import yaml


def enable_yaml_load(tag):
def yaml_load_decorator(cls):
def class_factory(loader, node):
settings = YAMLTagSettings.fetch(cls)
new_cls = cls
if isinstance(node, yaml.nodes.MappingNode):
parameters = loader.construct_mapping(node)
parameters = loader.construct_mapping(node, deep=settings.eager)
new_cls = cls(**parameters)
elif isinstance(node, yaml.nodes.ScalarNode):
new_cls = cls()
elif isinstance(node, yaml.nodes.SequenceNode):
parameters = loader.construct_sequence(node)
parameters = loader.construct_sequence(node, deep=settings.eager)
new_cls = cls(*parameters)
return new_cls

Expand Down
2 changes: 2 additions & 0 deletions tardis/utilities/executors/sshexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ...exceptions.executorexceptions import CommandExecutionFailure
from ...interfaces.executor import Executor
from ..attributedict import AttributeDict
from cobald.daemon.plugins import yaml_tag

import asyncio
import asyncssh
Expand Down Expand Up @@ -88,6 +89,7 @@ async def kbdint_challenge_received(


@enable_yaml_load("!SSHExecutor")
@yaml_tag(eager=True)
class SSHExecutor(Executor):
def __init__(self, **parameters):
self._parameters = dict(parameters)
Expand Down

0 comments on commit d9e781a

Please sign in to comment.