Skip to content

Commit

Permalink
Merge pull request #96 from lsst/tickets/DM-27519
Browse files Browse the repository at this point in the history
DM-27519: Improve printing of config history
  • Loading branch information
andy-slac committed Nov 15, 2020
2 parents cf8cecc + 537b115 commit f820c27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion python/lsst/ctrl/mpexec/cli/opt/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
`config=[Task::]<PATTERN>:NOIGNORECASE` to dump configuration
fields possibly matching given pattern and/or task label;
`history=<FIELD>` to dump configuration history for a field, field
name is specified as [Task::][SubTask.]Field; `dump-config`,
name is specified as [Task::]<PATTERN>; `dump-config`,
`dump-config=Task` to dump complete configuration for a task given
its label or all tasks; `pipeline` to show pipeline composition;
`graph` to show information about quanta; `workflow` to show
Expand Down
31 changes: 14 additions & 17 deletions python/lsst/ctrl/mpexec/cmdLineFwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,30 +765,27 @@ def _showConfigHistory(self, pipeline, showArgs):
if nmatch > 0:
print("")

partitioned = thisName.split(".")
cpath, cname = partitioned[:-1], partitioned[-1]

hconfig = config # the config that we're interested in

for i, cpt in enumerate(cpath):
# We know this should be available because we checked
# all the names above but we still might be caught out
try:
hconfig = getattr(hconfig, cpt)
except AttributeError:
config_path = ".".join(["config"] + cpath[:i])
print(f"Error: Unable to extract {cname} from {config_path} "
f"from task {taskDef.label}", file=sys.stderr)
hconfig = None
cpath, _, cname = thisName.rpartition(".")
try:
if not cpath:
# looking for top-level field
hconfig = taskDef.config
else:
hconfig = eval("config." + cpath, {}, {"config": config})
except AttributeError:
print(f"Error: Unable to extract attribute {cpath} from task {taskDef.label}",
file=sys.stderr)
hconfig = None

# Sometimes we end up with a non-Config so skip those
if isinstance(hconfig, pexConfig.Config) and hasattr(hconfig, cname):
if isinstance(hconfig, (pexConfig.Config, pexConfig.ConfigurableInstance)) and \
hasattr(hconfig, cname):
print(f"### Configuration field for task `{taskDef.label}'")
print(pexConfig.history.format(hconfig, cname))
found = True

if not found:
print(f"None of the tasks has field named {pattern}", file=sys.stderr)
print(f"None of the tasks has field matching {pattern}", file=sys.stderr)
sys.exit(1)

def _showTaskHierarchy(self, pipeline):
Expand Down

0 comments on commit f820c27

Please sign in to comment.