-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Stuff! | ||
|
||
foo bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
foo: bar | ||
|
||
return->: true | ||
|
||
should-not-be-here: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
foo: bar | ||
|
||
returns->: hello {{foo}} | ||
|
||
should-not-be-here: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(target str)<-: | ||
return->: target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
from typing import Any | ||
|
||
from tackle import BaseHook, Context, Field | ||
from tackle.factory import new_context | ||
from tackle.parser import walk_document | ||
from tackle.hooks import get_hook_from_context | ||
from tackle.parser import run_hook_exec | ||
|
||
|
||
class RunHookHook(BaseHook): | ||
"""Hook to run other hooks dynamically.""" | ||
|
||
hook_name: str = 'run_hook' | ||
hook: str = Field(..., description="The name of the hook to run.") | ||
hook_dict: dict = Field( | ||
None, | ||
description="A dict of keys to use with the hook.", | ||
) | ||
|
||
args: list = ['hook_name', 'hook_dict'] | ||
args: list = ['hook', 'hook_dict'] | ||
kwargs: str = 'hook_dict' | ||
|
||
def exec(self, context: 'Context') -> Any: | ||
# TODO: this can be done more easily if we have a clean way to just call a hook | ||
# without having to build a new context. Don't need to assemble if we just have | ||
# a simple hook call function. | ||
element = {'tmp': {context.key_path[-1]: self.hook_name, **self.hook_dict}} | ||
|
||
tmp_context = new_context( | ||
_hooks=context.hooks, | ||
existing_data=context.data.public, | ||
) | ||
tmp_context.key_path = ['->'] | ||
tmp_context.key_path_block = ['->'] | ||
tmp_context.hooks.public.update(context.hooks.public) | ||
tmp_context.hooks.private.update(context.hooks.private) | ||
|
||
walk_document(context=tmp_context, value=element) | ||
|
||
return tmp_context.data.public['tmp'] | ||
Hook = get_hook_from_context(context, hook_name=self.hook, args=[], throw=True) | ||
return run_hook_exec(context, Hook(**self.hook_dict)) |
8 changes: 2 additions & 6 deletions
8
providers/tackle/tests/tackle/kwargs-default-hook-target.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
|
||
<-: | ||
foo: str | ||
args: ['foo'] | ||
exec: | ||
v->: var {{foo}} | ||
(foo str)<-: | ||
v->: var {{foo}} |
This file was deleted.
Oops, something went wrong.