in tools/tensorflow_docs/tools/nblint/linter.py [0:0]
def _run_lint_group(self, lint: decorator.Lint, lint_args: Dict[str, Any],
data: Dict[str, Any],
status: "LinterStatus") -> Tuple[bool, Set[str]]:
"""Run lint over all cells with scope and return cumulative pass/fail.
Args:
lint: `decorator.Lint` containg the assertion, scope, and condition.
lint_args: Nested dictionary of args to pass the lint callback function.
data: `dict` containing data of entire parse notebook.
status: The `LinterStatus` to add individual entries for group members.
Returns:
Boolean: True if lint passes for all/any cells, otherwise False.
Set: Deduplicated list of failure message strings.
Raises:
Exception: Unsupported lint condition in `decorator.Options.Cond`.
"""
scope: decorator.Options.Scope = lint.scope
# Return value of each (scoped) cell in notebook.
is_success_list: List[bool] = []
# All conditional failure messages from lint function (deduplicated).
cond_fail_message_list: Set[str] = set()
for cell_idx, cell in enumerate(data.get("cells")):
# Evict notebook cells outside of scope.
cell_type = cell.get("cell_type")
if scope is decorator.Options.Scope.TEXT and cell_type != "markdown":
continue
elif scope is decorator.Options.Scope.CODE and cell_type != "code":
continue
# Add cell-specific data to args passed to lint callback.
lint_args["cell_data"] = cell
lint_args["cell_source"] = "".join(cell["source"])
# Execute lint on cell and collect result.
run_status = self._run_lint(lint, lint_args, status)
is_success_list.append(run_status.is_success)
if run_status.cond_fail_msg:
cond_fail_message_list.add(run_status.cond_fail_msg)
# All lint runs get a status entry. Group success is a separate entry.
name = f"{lint.name}__cell_{cell_idx}"
status.add_entry(
lint, run_status, name=name, group=lint.name, is_group_entry=True)
# Return True/False success for entire cell group.
if lint.cond is decorator.Options.Cond.ANY:
return any(is_success_list), cond_fail_message_list
elif lint.cond is decorator.Options.Cond.ALL:
return all(is_success_list), cond_fail_message_list
else:
raise Exception("Unsupported lint condition.")