Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to display the executor output #491

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 48 additions & 1 deletion tango/executor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -46,6 +49,50 @@ class ExecutorOutput:
not_run: Dict[str, ExecutionMetadata] = field(default_factory=dict)
"""Steps that were ignored (usually because of failed dependencies)."""

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")
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}[/]"
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):
"""
Expand Down