Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ncilfone committed Jul 13, 2021
1 parent 454c431 commit 8032c5e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spock/backend/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def _make_group_override_parser(parser, class_obj, class_name):
)
# If it's a reference to a class it needs to be an arg of a simple string as class matching will take care
# of it later on
elif val_type.__module__ == 'spock.backend.config':
elif val_type.__module__ == "spock.backend.config":
arg_name = f"--{str(attr_name)}.{val.name}"
val_type = str
group_parser = make_argument(arg_name, val_type, group_parser)
Expand Down
23 changes: 19 additions & 4 deletions spock/backend/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ def _handle_payload_override(payload, key, value):
key_split = key.split(".")
curr_ref = payload
# Handle non existing parts of the payload for specific cases
root_classes = [idx for idx, val in enumerate(key_split) if hasattr(sys.modules["spock"].backend.config, val)]
root_classes = [
idx
for idx, val in enumerate(key_split)
if hasattr(sys.modules["spock"].backend.config, val)
]
# Verify any classes have roots in the payload dict
for idx in root_classes:
# Update all root classes if not present
Expand All @@ -405,13 +409,24 @@ def _handle_payload_override(payload, key, value):
# Make sure it's there by setting it -- since this is an override setting is fine as these should be the
# final say in the param values so don't worry about clashing
if idx != 0:
payload[key_split[0]][key_split[idx-1]] = key_split[idx]
payload[key_split[0]][key_split[idx - 1]] = key_split[idx]
# Check also for repeated classes -- value will be a list when the type is not
var = getattr(getattr(sys.modules["spock"].backend.config, key_split[idx]).__attrs_attrs__, key_split[-1])
var = getattr(
getattr(
sys.modules["spock"].backend.config, key_split[idx]
).__attrs_attrs__,
key_split[-1],
)
if isinstance(value, list) and var.type != list:
# If the dict is blank we need to handle the creation of the list of dicts
if len(payload[key_split[idx]]) == 0:
payload.update({key_split[idx]: [{key_split[-1]: None} for _ in range(len(value))]})
payload.update(
{
key_split[idx]: [
{key_split[-1]: None} for _ in range(len(value))
]
}
)
# If it's already partially filled we need to update not overwrite
else:
for val in payload[key_split[idx]]:
Expand Down
6 changes: 5 additions & 1 deletion spock/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ def _get_payload(self, payload_obj, input_classes, ignore_args: typing.List):
if len(self._args.config) > 0:
for configs in self._args.config:
payload_update = payload_obj.payload(
input_classes, ignore_args, configs, self._args, dependencies
input_classes,
ignore_args,
configs,
self._args,
dependencies,
)
check_payload_overwrite(payload, payload_update, configs)
deep_payload_update(payload, payload_update)
Expand Down

0 comments on commit 8032c5e

Please sign in to comment.