Skip to content

Commit 43174b5

Browse files
feat: add compatibility with pytask v0.6.0 (#153)
* feat: add compatibility with pytask v0.6.0 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix * Mark trace test xfail on Python 3.14 in GitHub Actions --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a03c33f commit 43174b5

9 files changed

Lines changed: 45 additions & 24 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ repos:
5656
args: [--wrap, "88"]
5757
files: (README\.md)
5858
- repo: https://github.com/crate-ci/typos
59-
rev: v1
59+
rev: v1.46.0
6060
hooks:
6161
- id: typos
6262
- repo: meta

‎docs/source/changes.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask-parallel) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask-parallel).
77

8+
## 0.5.3 - 2026-05-01
9+
10+
- {pull}`153` adds compatibility with the new pytask 0.6.0 release.
11+
812
## 0.5.2 - 2026-02-06
913

1014
- {pull}`129` drops support for Python 3.8 and 3.9 and adds support for Python 3.14.

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ unsafe-fixes = true
9999

100100
[tool.ruff.lint]
101101
extend-ignore = [
102-
"ANN401", # flake8-annotate typing.Any
103102
"COM812", # Comply with ruff-format.
104103
"ISC001", # Comply with ruff-format.
105104
]

‎src/pytask_parallel/backends.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _configure_worker(root: str | None) -> None:
6363
sys.path.insert(0, root)
6464

6565

66-
def _deserialize_and_run_with_cloudpickle(fn: bytes, kwargs: bytes) -> Any:
66+
def _deserialize_and_run_with_cloudpickle(fn: bytes, kwargs: bytes) -> Any: # noqa: ANN401
6767
"""Deserialize and execute a function and keyword arguments."""
6868
deserialized_fn = cloudpickle.loads(fn)
6969
deserialized_kwargs = cloudpickle.loads(kwargs)
@@ -77,8 +77,8 @@ def submit(
7777
self,
7878
fn: Callable[..., Any],
7979
/,
80-
*args: Any, # noqa: ARG002
81-
**kwargs: Any,
80+
*args: Any, # noqa: ANN401, ARG002
81+
**kwargs: Any, # noqa: ANN401
8282
) -> Future[Any]:
8383
"""Submit a new task."""
8484
return super().submit(

‎src/pytask_parallel/execute.py‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@
4141
from pytask_parallel.wrappers import WrapperResult
4242

4343

44+
def _get_task_from_dag(session: Session, task_name: str) -> PTask:
45+
"""Get a task from the pre- and post-pytask 0.6 DAG representations for compat."""
46+
node = session.dag.nodes[task_name]
47+
task = node["task"] if isinstance(node, dict) else node
48+
49+
if not isinstance(task, PTask):
50+
msg = f"Expected {task_name!r} to resolve to a task."
51+
raise TypeError(msg)
52+
53+
return task
54+
55+
4456
@hookimpl
4557
def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR0912, PLR0915
4658
"""Execute tasks with a parallel backend.
@@ -68,8 +80,13 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
6880
with session.config["_parallel_executor"]:
6981
sleeper = _Sleeper()
7082

83+
scheduler = session.scheduler
84+
if scheduler is None:
85+
msg = "Expected the scheduler to be initialized before executing tasks."
86+
raise RuntimeError(msg)
87+
7188
i = 0
72-
while session.scheduler.is_active():
89+
while scheduler.is_active():
7390
try:
7491
newly_collected_reports = []
7592

@@ -88,13 +105,11 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
88105
n_new_tasks = session.config["n_workers"] - len(running_tasks)
89106

90107
ready_tasks = (
91-
list(session.scheduler.get_ready(n_new_tasks))
92-
if n_new_tasks >= 1
93-
else []
108+
list(scheduler.get_ready(n_new_tasks)) if n_new_tasks >= 1 else []
94109
)
95110

96111
for task_name in ready_tasks:
97-
task = session.dag.nodes[task_name]["task"]
112+
task = _get_task_from_dag(session, task_name)
98113
session.hook.pytask_execute_task_log_start(
99114
session=session, task=task
100115
)
@@ -111,7 +126,7 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
111126
task, sys.exc_info()
112127
)
113128
newly_collected_reports.append(report)
114-
session.scheduler.done(task_name)
129+
scheduler.done(task_name)
115130

116131
if not ready_tasks:
117132
sleeper.increment()
@@ -133,17 +148,17 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
133148
)
134149

135150
if wrapper_result.exc_info is not None:
136-
task = session.dag.nodes[task_name]["task"]
151+
task = _get_task_from_dag(session, task_name)
137152
newly_collected_reports.append(
138153
ExecutionReport.from_task_and_exception(
139154
task,
140155
cast("Any", wrapper_result.exc_info),
141156
)
142157
)
143158
running_tasks.pop(task_name)
144-
session.scheduler.done(task_name)
159+
scheduler.done(task_name)
145160
else:
146-
task = session.dag.nodes[task_name]["task"]
161+
task = _get_task_from_dag(session, task_name)
147162
_update_carry_over_products(
148163
task, wrapper_result.carry_over_products
149164
)
@@ -161,7 +176,7 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
161176

162177
running_tasks.pop(task_name)
163178
newly_collected_reports.append(report)
164-
session.scheduler.done(task_name)
179+
scheduler.done(task_name)
165180

166181
for report in newly_collected_reports:
167182
session.hook.pytask_execute_task_process_report(

‎src/pytask_parallel/nodes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ def load(self, is_product: bool = False) -> Path: # noqa: ARG002, FBT001, FBT00
7171
self.node.path = path
7272
return self.node.load(is_product=self.is_product)
7373

74-
def save(self, value: Any) -> None:
74+
def save(self, value: Any) -> None: # noqa: ANN401
7575
"""Save strings or bytes to file."""
7676
self.value = value

‎src/pytask_parallel/typing.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Contains functions related to typing."""
22

3-
from pathlib import Path
43
from pathlib import PosixPath
54
from pathlib import WindowsPath
5+
from typing import Any
66
from typing import NamedTuple
77

88
from pytask import PTask
@@ -16,7 +16,7 @@ def is_coiled_function(task: PTask) -> bool:
1616
return "coiled_kwargs" in task.attributes
1717

1818

19-
def is_local_path(path: Path) -> bool:
19+
def is_local_path(path: Any) -> bool: # noqa: ANN401
2020
"""Check if a path is local."""
2121
return isinstance(path, (FilePath, PosixPath, WindowsPath))
2222

‎src/pytask_parallel/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _safe_load(
7373
*,
7474
is_product: bool,
7575
remote: bool,
76-
) -> Any:
76+
) -> Any: # noqa: ANN401
7777
"""Load a node and catch exceptions."""
7878
_rich_traceback_guard = True
7979
# Get the argument name like "path" or "return" for function returns.

‎src/pytask_parallel/wrappers.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class WrapperResult:
5757
stderr: str
5858

5959

60-
def wrap_task_in_thread(task: PTask, *, remote: bool, **kwargs: Any) -> WrapperResult:
60+
def wrap_task_in_thread(task: PTask, *, remote: bool, **kwargs: Any) -> WrapperResult: # noqa: ANN401
6161
"""Mock execution function such that it returns the same as for processes.
6262
6363
The function for processes returns ``warning_reports`` and an ``exception``. With
@@ -191,7 +191,7 @@ def rewrap_task_with_coiled_function(task: PTask) -> CoiledFunction:
191191
return cast("CoiledFunction", decorated)
192192

193193

194-
def _raise_exception_on_breakpoint(*args: Any, **kwargs: Any) -> None: # noqa: ARG001
194+
def _raise_exception_on_breakpoint(*args: Any, **kwargs: Any) -> None: # noqa: ANN401, ARG001
195195
msg = (
196196
"You cannot use 'breakpoint()' or 'pdb.set_trace()' while parallelizing the "
197197
"execution of tasks with pytask-parallel. Please, remove the breakpoint or run "
@@ -223,11 +223,14 @@ def _render_traceback_to_string(
223223
traceback = Traceback(exc_info, show_locals=show_locals)
224224
segments = console.render(cast("Any", traceback), options=console_options)
225225
text = "".join(segment.text for segment in segments)
226-
return (*exc_info[:2], text)
226+
return exc_info[0], exc_info[1], text
227227

228228

229229
def _handle_function_products(
230-
task: PTask, out: Any, *, remote: bool = False
230+
task: PTask,
231+
out: Any, # noqa: ANN401
232+
*,
233+
remote: bool = False,
231234
) -> PyTree[CarryOverPath | PythonNode | None]:
232235
"""Handle the products of the task.
233236
@@ -310,7 +313,7 @@ def _delete_local_files_on_remote(kwargs: dict[str, PyTree[Any]]) -> None:
310313
311314
"""
312315

313-
def _delete(potential_node: Any) -> None:
316+
def _delete(potential_node: Any) -> None: # noqa: ANN401
314317
if isinstance(potential_node, RemotePathNode):
315318
with suppress(OSError):
316319
os.close(potential_node.fd)

0 commit comments

Comments
 (0)