From 609c065fd767f9ad55cc22a1bc54c1919167af6d Mon Sep 17 00:00:00 2001 From: Tanmay Gupta Date: Fri, 9 Dec 2022 15:03:09 -0800 Subject: [PATCH 1/3] Update executor.py Add ability to display the executor output. Can be used as follows: ```python output = executor.execute_step_graph(step_graph) output.display() ``` --- tango/executor.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tango/executor.py b/tango/executor.py index 91480dcaf..a9cca8823 100644 --- a/tango/executor.py +++ b/tango/executor.py @@ -45,6 +45,57 @@ class ExecutorOutput: not_run: Dict[str, ExecutionMetadata] = field(default_factory=dict) """Steps that were ignored (usually because of failed dependencies).""" + + def display(self): + from rich.console import Console + from rich.table import Table + + table = Table(caption_style="") + table.add_column("Step Name", justify="left", style="cyan") + table.add_column("Status", justify="left") + table.add_column("Results", justify="left") + last_cached_step: Optional[str] = None + all_steps = dict(self.successful) + all_steps.update(self.failed) + all_steps.update(self.not_run) + for step_name in sorted(all_steps): + status_str: str + result_str: str = "[grey62]N/A[/]" + if step_name in self.failed: + status_str = "[red]\N{ballot x} failed[/]" + execution_metadata = self.failed[step_name] + if execution_metadata.logs_location is not None: + result_str = f"[cyan]{execution_metadata.logs_location}[/]" + elif step_name in self.not_run: + status_str = "[yellow]- not run[/]" + elif step_name in self.successful: + status_str = "[green]\N{check mark} succeeded[/]" + execution_metadata = self.successful[step_name] + if execution_metadata.result_location is not None: + result_str = f"[cyan]{execution_metadata.result_location}[/]" + last_cached_step = step_name + elif execution_metadata.logs_location is not None: + result_str = f"[cyan]{execution_metadata.logs_location}[/]" + else: + continue + + table.add_row(step_name, status_str, result_str) + + caption_parts: List[str] = [] + if self.failed: + caption_parts.append( + f"[red]\N{ballot x}[/] [italic]{len(self.failed)} failed[/]" + ) + if self.successful: + caption_parts.append( + f"[green]\N{check mark}[/] [italic]{len(self.successful)} succeeded[/]" + ) + if self.not_run: + caption_parts.append(f"[italic]{len(self.not_run)} not run[/]") + table.caption = ", ".join(caption_parts) + + console = Console() + console.print(table) class Executor(Registrable): From 40c28c5853bdd8a37771139e221a5fa5f61d3203 Mon Sep 17 00:00:00 2001 From: Tanmay Gupta Date: Fri, 9 Dec 2022 16:58:27 -0800 Subject: [PATCH 2/3] fix formating --- tango/executor.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tango/executor.py b/tango/executor.py index a9cca8823..62659ac04 100644 --- a/tango/executor.py +++ b/tango/executor.py @@ -1,7 +1,10 @@ import logging import warnings from dataclasses import dataclass, field -from typing import TYPE_CHECKING, Dict, Optional, Sequence, TypeVar +from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, TypeVar + +from rich.console import Console +from rich.table import Table from .common.logging import log_exception from .common.registrable import Registrable @@ -45,16 +48,12 @@ class ExecutorOutput: not_run: Dict[str, ExecutionMetadata] = field(default_factory=dict) """Steps that were ignored (usually because of failed dependencies).""" - - def display(self): - from rich.console import Console - from rich.table import Table + def display(self) -> None: table = Table(caption_style="") table.add_column("Step Name", justify="left", style="cyan") table.add_column("Status", justify="left") table.add_column("Results", justify="left") - last_cached_step: Optional[str] = None all_steps = dict(self.successful) all_steps.update(self.failed) all_steps.update(self.not_run) @@ -73,19 +72,16 @@ def display(self): execution_metadata = self.successful[step_name] if execution_metadata.result_location is not None: result_str = f"[cyan]{execution_metadata.result_location}[/]" - last_cached_step = step_name elif execution_metadata.logs_location is not None: result_str = f"[cyan]{execution_metadata.logs_location}[/]" else: continue table.add_row(step_name, status_str, result_str) - + caption_parts: List[str] = [] if self.failed: - caption_parts.append( - f"[red]\N{ballot x}[/] [italic]{len(self.failed)} failed[/]" - ) + caption_parts.append(f"[red]\N{ballot x}[/] [italic]{len(self.failed)} failed[/]") if self.successful: caption_parts.append( f"[green]\N{check mark}[/] [italic]{len(self.successful)} succeeded[/]" From 78e60699558b4c99646f6c2b9a538f9474c0f488 Mon Sep 17 00:00:00 2001 From: Tanmay Gupta Date: Fri, 9 Dec 2022 17:05:19 -0800 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2898e932c..d3d22257b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - You can now add arguments to steps without invalidating the cache. See `Step.SKIP_DEFAULT_ARGUMENTS`. - +- Added `display()` to `ExecutorOutput` for producing a table that summarizes the run ## [v1.1.0](https://github.com/allenai/tango/releases/tag/v1.1.0) - 2022-12-01