Skip to content

Commit

Permalink
rf: consume _process_results(), no longer needed as a separate func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
mih committed Sep 10, 2024
1 parent 6dce645 commit 02541a9
Showing 1 changed file with 38 additions and 57 deletions.
95 changes: 38 additions & 57 deletions datalad_next/patches/interface_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,28 +535,51 @@ def _execute_command_(
allkwargs:
Keyword arguments for `cmd`.
"""
# flag whether to raise an exception
# bookkeeping whether to raise an exception
incomplete_results: list[dict] = []

on_failure = allkwargs['on_failure']

# process main results
for r in _process_results(
# execution, call with any arguments from the validated
# set that are no result-handling related
cmd(**{k: v for k, v in allkwargs.items()
if k not in eval_params}),
on_failure=allkwargs['on_failure'],
# bookkeeping
incomplete_results=incomplete_results,
# communication
result_logger=result_handler.log_result,
result_renderer=result_handler.render_result,
# execution, call with any arguments from the validated
# set that are no result-handling related
for res in cmd(
**{k: v for k, v in allkwargs.items()
if k not in eval_params}
):
yield from result_handler.run_result_hooks(r)
if not res or 'action' not in res:
# XXX: Yarik has to no clue on how to track the origin of the
# record to figure out WTF, so he just skips it
# but MIH thinks leaving a trace of that would be good
lgr.debug('Drop result record without "action": %s', res)
continue

result_handler.log_result(res)
# remove logger instance from results, as it is no longer useful
# after logging was done, it isn't serializable, and generally
# pollutes the output
res.pop('logger', None)

# output rendering
result_handler.render_result(res)

if not result_handler.keep_result(r):
# error handling
# looks for error status, and report at the end via
# an exception
if on_failure in ('continue', 'stop') \
and res['status'] in ('impossible', 'error'):
incomplete_results.append(res)
if on_failure == 'stop':
# first fail -> that's it
# raise will happen after the loop
break

yield from result_handler.run_result_hooks(res)

if not result_handler.keep_result(res):
continue

yield from result_handler.transform_result(r)
yield from result_handler.transform_result(res)

result_handler.render_result_summary()

Expand Down Expand Up @@ -628,48 +651,6 @@ def get_hooks(dataset_arg: Any) -> dict[str, dict]:
return get_jsonhooks_from_config(ds.config if ds else dlcfg)


def _process_results(
results,
*,
on_failure: str,
incomplete_results,
result_logger: Callable,
result_renderer: Callable,
):
# private helper pf @eval_results
# loop over results generated from some source and handle each
# of them according to the requested behavior (logging, rendering, ...)

for res in results:
if not res or 'action' not in res:
# XXX: Yarik has to no clue on how to track the origin of the
# record to figure out WTF, so he just skips it
# but MIH thinks leaving a trace of that would be good
lgr.debug('Drop result record without "action": %s', res)
continue

result_logger(res)
# remove logger instance from results, as it is no longer useful
# after logging was done, it isn't serializable, and generally
# pollutes the output
res.pop('logger', None)

# output rendering
result_renderer(res)

# error handling
# looks for error status, and report at the end via
# an exception
if on_failure in ('continue', 'stop') \
and res['status'] in ('impossible', 'error'):
incomplete_results.append(res)
if on_failure == 'stop':
# first fail -> that's it
# raise will happen after the loop
break
yield res


def _display_suppressed_message(nsimilar, ndisplayed, last_ts, final=False):
# +1 because there was the original result + nsimilar displayed.
n_suppressed = nsimilar - ndisplayed + 1
Expand Down

0 comments on commit 02541a9

Please sign in to comment.