Skip to content

Commit

Permalink
fix: make context hooks sep a dot by default vs slash
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Dec 7, 2024
1 parent e96abc0 commit 49c8df9
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion providers/context/hooks/append.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppendHook(BaseHook):
"to within the context.")
src_is_key_path: bool = Field(
False, description="If the src is a list and is meant to be a key path.")
sep: str = Field('/', description="For string src's, a separator for key path.")
sep: str = Field('.', description="For string src's, a separator for key path.")
# item: Union[str, list, dict, int, float, bool] = Field(
# ..., description="An item to append to a list."
# )
Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeleteKeyHook(BaseHook):
..., description="A list or string with a separator for the path to the value "
"you want to update with strings for keys and ints for "
"indexes in the list.")
sep: str = Field('/', description="For string paths, a separator for key path.")
sep: str = Field('.', description="For string paths, a separator for key path.")
args: list = ['path']
# fmt: on

Expand Down
8 changes: 4 additions & 4 deletions providers/context/hooks/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GetKeyHook(BaseHook):
"want to update with strings for keys and ints for indexes in the "
"list."
)
sep: str = Field('/', description="For string paths, a separator for key path.")
sep: str = Field('.', description="For string paths, a separator for key path.")
fallback: Any = Field(
FALLBACK_VALUE, description="Fallback value if the keys is not found."
)
Expand All @@ -45,15 +45,15 @@ def exec(self, context: Context):
if value is not None:
break

if value is None and self.verbose:
if self.verbose:
if value is None and context.verbose:
if context.verbose:
print(f"Could not find a key in {self.path} in any context.")
if self.fallback == FALLBACK_VALUE:
raise HookCallException(
f"Could not find a key in {self.path} in any context.",
context=context,
)
if self.verbose:
if context.verbose:
print(f"Using fallback={self.fallback}.")
value = self.fallback

Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DictKeysHook(BaseHook):
# fmt: off
src: Union[dict, str, list] = Field(
description="A dict to get the keys from and output the result or a str with separators or list for a key path to the element to get the keys from within the context.")
sep: str = Field('/', description="For string src's, a separator for key path.")
sep: str = Field('.', description="For string src's, a separator for key path.")
# fmt: on

args: list = ['src']
Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DictPopHook(BaseHook):
description="A string for a key to remove from a dict `src` or integer for an "
"index to remove from a list `src`.",
)
sep: str = Field('/', description="For string src's, a separator for key path.")
sep: str = Field('.', description="For string src's, a separator for key path.")
# fmt: on

args: list = ['src', 'item']
Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SetKeyHook(BaseHook):
# fmt: off
path: Any = Field(..., description="A list or string with a separator for the path to the value you want to update with strings for keys and ints for indexes in the list.")
value: Any = Field(..., description="The value to update the key with.")
sep: str = Field('/', description="For string paths, a separator for key path.")
sep: str = Field('.', description="For string paths, a separator for key path.")
args: list = ['path', 'value']
# fmt: on

Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DictUpdateHook(BaseHook):
description="A dict to update and output the result or a str with separators "
"or list for a key path to the item update within the context.")
input: Any = Field(description="The value to update the input `src`.")
sep: str = Field('/', description="For string src's, a separator for key path.")
sep: str = Field('.', description="For string src's, a separator for key path.")
# fmt: on

args: list = ['src', 'input']
Expand Down
2 changes: 1 addition & 1 deletion providers/context/hooks/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DictValuesHook(BaseHook):
# fmt: off
src: Union[dict, str, list] = Field(
description="A dict to get the values from and output the result or a str with separators or list for a key path to the element to get the values from within the context.")
sep: str = Field('/', description="For string src's, a separator for key path.")
sep: str = Field('.', description="For string src's, a separator for key path.")
# fmt: on

args: list = ['src']
Expand Down
2 changes: 1 addition & 1 deletion providers/context/tests/append.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ output->: append {{list}} foo

output_list->: append {{list}} ['foo']

in place_>: append path/to/list foo
in place_>: append path.to.list foo
6 changes: 3 additions & 3 deletions providers/context/tests/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ deleter_list:

deleter_str:
->: delete
path: two/0/that/stuff
path: two.0.that.stuff

deleter_str_sep:
->: delete
path: three.0.that.stuff
sep: .
path: three/0/that/stuff
sep: /
6 changes: 3 additions & 3 deletions providers/context/tests/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ getter_list:

getter_str:
->: get
path: two/0/that/stuff
path: two.0.that.stuff

getter_str_sep:
->: get
path: three.0.that.stuff
sep: .
path: three/0/that/stuff
sep: /
2 changes: 1 addition & 1 deletion providers/context/tests/keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ another_map:
stuff: foo
things: bar

key_path_>: keys another_map/key
key_path_>: keys another_map.key

check_key_path->: assert {{key_path}} ["stuff","things"]
2 changes: 1 addition & 1 deletion providers/context/tests/pop-in-place.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ embedded:
- stuff
- things

pop embedded list_>: pop embedded/list
pop embedded list_>: pop embedded.list
pop list_>: pop list 0
6 changes: 3 additions & 3 deletions providers/context/tests/set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ setter_list:

setter_str:
->: set
path: two/0/that/stuff
path: two.0.that.stuff
value: more things

setter_str_sep:
->: set
path: three.0.that.stuff
path: three/0/that/stuff
value: more things
sep: .
sep: /
2 changes: 1 addition & 1 deletion providers/context/tests/update-reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ update_map:
input:
stuff: "{{ dict_map }}"

update in place_>: update dict_map/foo bar
update in place_>: update dict_map.foo bar
4 changes: 2 additions & 2 deletions providers/context/tests/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ input:
map:
stuff: things
#update with string in place_>: update input/map "more things"
update with map in place_>: update input/map {'foo':'bar'}
update with map in place_>: update input.map {'foo':'bar'}


input_map:
Expand Down Expand Up @@ -32,7 +32,7 @@ arg->: update "{{ input_map }}" "{{ dict_map }}"

arg2->: update {{input_map}} {'stuff':{{dict_map}}}

update in place_>: update dict_map/foo bar
update in place_>: update dict_map.foo bar
update in place list_>: update ['dict_map','bar'] bar

update_ref->: update input_map {{new_map}}
Expand Down
2 changes: 1 addition & 1 deletion providers/context/tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ another_map:
things:
bar: baz

key_path_>: values another_map/key
key_path_>: values another_map.key

check_key_path->: assert {{key_path}} ["foo",{"bar":"baz"}]

0 comments on commit 49c8df9

Please sign in to comment.