Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

## Unreleased

- [#837](https://github.com/pytask-dev/pytask/pull/837) skips incremental live
rendering on non-interactive output while preserving the final build table and
live-manager lifecycle.
- [#836](https://github.com/pytask-dev/pytask/pull/836) hardens GitHub Actions
workflows with zizmor, pinned action SHAs, explicit permissions, and a dedicated
code-scanning upload workflow.
Expand Down
18 changes: 14 additions & 4 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ def pytask_post_parse(config: dict[str, Any]) -> None:
n_entries_in_table=config["n_entries_in_table"],
verbose=config["verbose"],
editor_url_scheme=config["editor_url_scheme"],
render_immediately=console.is_interactive,
sort_final_table=config["sort_table"],
)
config["pm"].register(live_execution, "live_execution")

live_collection = LiveCollection(live_manager=live_manager)
live_collection = LiveCollection(
live_manager=live_manager, render_immediately=console.is_interactive
)
config["pm"].register(live_collection, "live_collection")


Expand Down Expand Up @@ -187,6 +190,7 @@ class LiveExecution:
editor_url_scheme: str
initial_status: TaskExecutionStatus = TaskExecutionStatus.RUNNING
sort_final_table: bool = False
render_immediately: bool = True
n_tasks: int | str = "x"
_reports: list[_ReportEntry] = field(default_factory=list)
_running_tasks: dict[str, _TaskEntry] = field(default_factory=dict)
Expand Down Expand Up @@ -306,12 +310,14 @@ def add_task(self, new_running_task: PTask, status: TaskExecutionStatus) -> None
self._running_tasks[new_running_task.signature] = _TaskEntry(
task=new_running_task, status=status
)
self._update_table()
if self.render_immediately:
self._update_table()

def update_task(self, signature: str, status: TaskExecutionStatus) -> None:
"""Update the status of a running task."""
self._running_tasks[signature].status = status
self._update_table()
if self.render_immediately:
self._update_table()

def update_report(self, new_report: ExecutionReport) -> None:
"""Update the status of a running task by adding its report."""
Expand All @@ -323,14 +329,16 @@ def update_report(self, new_report: ExecutionReport) -> None:
task=new_report.task,
)
)
self._update_table()
if self.render_immediately:
self._update_table()


@dataclass(eq=False, kw_only=True)
class LiveCollection:
"""A class for managing the live status during the collection."""

live_manager: LiveManager
render_immediately: bool = True
_n_collected_tasks: int = 0
_n_errors: int = 0

Expand Down Expand Up @@ -362,6 +370,8 @@ def _update_statistics(self, reports: list[CollectionReport]) -> None:

def _update_status(self) -> None:
"""Update the status."""
if not self.render_immediately:
return
status = self._generate_status()
self.live_manager.update(status)

Expand Down
Loading