Skip to content

Commit

Permalink
Improve control over repr parameters when empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Jan 23, 2023
1 parent 06c6b66 commit 991208f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions law/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class Task(six.with_metaclass(Register, BaseTask)):
exclude_index = True
exclude_params_req = set()
exclude_params_repr = set()
exclude_params_repr_empty = set()

@classmethod
def req_params(cls, inst, _exclude=None, _prefer_cli=None, **kwargs):
Expand Down Expand Up @@ -595,8 +596,14 @@ def _repr_params(self, all_params=False):
# build a map "name -> value" for all significant parameters
params = OrderedDict()
for name, param in self.get_params():
if param.significant and not multi_match(name, exclude):
params[name] = getattr(self, name)
value = getattr(self, name)
include = (
param.significant and
not multi_match(name, exclude) and
(name not in self.exclude_params_repr_empty or value)
)
if include:
params[name] = value

return params

Expand Down
6 changes: 4 additions & 2 deletions law/workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,10 @@ def _repr_params(self, *args, **kwargs):

if self.is_workflow():
# when this is a workflow, add the workflow type
if "workflow" not in params:
params["workflow"] = self.workflow
params.setdefault("workflow", self.workflow)
# skip branches when empty
if not params.get("branches"):
params.pop("branches", None)
else:
# when this is a branch, remove workflow parameters
for param in self.exclude_params_branch:
Expand Down

0 comments on commit 991208f

Please sign in to comment.