Skip to content

Allow setting task status in pytask_execute_task_log_start. #696

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

Open
wants to merge 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
releases are available on [PyPI](https://pypi.org/project/pytask) and
[Anaconda.org](https://anaconda.org/conda-forge/pytask).

## 0.5.6 - 2025-xx-xx

- {pull}`696` allows setting the status of a task in the `pytask_execute_task_log_start` hook which enables pending tasks to be displayed by pytask-parallel.

## 0.5.5 - 2025-07-25

- {pull}`692` documents how to use pytask with workspaces.
Expand Down
5 changes: 4 additions & 1 deletion src/_pytask/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from _pytask.exceptions import ExecutionError
from _pytask.exceptions import NodeLoadError
from _pytask.exceptions import NodeNotFoundError
from _pytask.logging_utils import TaskExecutionStatus
from _pytask.mark import Mark
from _pytask.mark_utils import has_mark
from _pytask.node_protocols import PNode
Expand Down Expand Up @@ -99,7 +100,9 @@ def pytask_execute_build(session: Session) -> bool | None:
@hookimpl
def pytask_execute_task_protocol(session: Session, task: PTask) -> ExecutionReport:
"""Follow the protocol to execute each task."""
session.hook.pytask_execute_task_log_start(session=session, task=task)
session.hook.pytask_execute_task_log_start(
session=session, task=task, status=TaskExecutionStatus.RUNNING
)
try:
session.hook.pytask_execute_task_setup(session=session, task=task)
session.hook.pytask_execute_task(session=session, task=task)
Expand Down
5 changes: 4 additions & 1 deletion src/_pytask/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import click
from pluggy import PluginManager

from _pytask.logging_utils import TaskExecutionStatus
from _pytask.models import NodeInfo
from _pytask.node_protocols import PNode
from _pytask.node_protocols import PProvisionalNode
Expand Down Expand Up @@ -255,7 +256,9 @@ def pytask_execute_task_protocol(session: Session, task: PTask) -> ExecutionRepo


@hookspec(firstresult=True)
def pytask_execute_task_log_start(session: Session, task: PTask) -> None:
def pytask_execute_task_log_start(
session: Session, task: PTask, status: TaskExecutionStatus
) -> None:
"""Start logging of task execution.

This hook can be used to provide more verbose output during the execution.
Expand Down
9 changes: 5 additions & 4 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from _pytask.console import console
from _pytask.console import format_task_name
from _pytask.logging_utils import TaskExecutionStatus
from _pytask.outcomes import CollectionOutcome
from _pytask.outcomes import Exit
from _pytask.outcomes import TaskOutcome
Expand All @@ -29,6 +28,7 @@
if TYPE_CHECKING:
from collections.abc import Generator

from _pytask.logging_utils import TaskExecutionStatus
from _pytask.node_protocols import PTask
from _pytask.reports import CollectionReport
from _pytask.reports import ExecutionReport
Expand Down Expand Up @@ -165,7 +165,6 @@ class LiveExecution:
n_entries_in_table: int
verbose: int
editor_url_scheme: str
initial_status: TaskExecutionStatus = TaskExecutionStatus.RUNNING
sort_final_table: bool = False
n_tasks: int | str = "x"
_reports: list[_ReportEntry] = field(factory=list)
Expand All @@ -186,9 +185,11 @@ def pytask_execute_build(self) -> Generator[None, None, None]:
console.print(table)

@hookimpl(tryfirst=True)
def pytask_execute_task_log_start(self, task: PTask) -> bool:
def pytask_execute_task_log_start(
self, task: PTask, status: TaskExecutionStatus
) -> bool:
"""Mark a new task as running."""
self.add_task(new_running_task=task, status=self.initial_status)
self.add_task(new_running_task=task, status=status)
return True

@hookimpl
Expand Down
Loading