def apply_from()

in runtool/runtool/transformations.py [0:0]


def apply_from(node: dict, context: dict) -> dict:
    """
    Update the node with the data which the path in node['$from'] is pointing to in the context dictionary.
    i.e.

    >>> apply_from(
    ...     node={"$from": "another_node.a_key", "some_key": "some_value"},
    ...     context={"another_node": {"a_key": {"hello": "world"}}}
    ... )
    {'hello': 'world', 'some_key': 'some_value'}

    Parameters
    ----------
    node
        The node which should be processed.
    context:
        Data which can be referenced by the path in node["$from"].
    Returns
    -------
    Dict
        the `node` updated with values from `context[node["from"]]`
    """
    if not (isinstance(node, dict) and "$from" in node):
        return node

    source = get_item_from_path(context, node.pop("$from"))

    # resolve any $from in the node we inherit from
    # this is to avoid updating the node with a new $from
    source = recursive_apply(source, partial(apply_from, context=context))

    assert isinstance(
        source, dict
    ), "$from can only be used to inherit from a dict"

    return update_nested_dict(source, node)