Skip to content

Commit 1ceb379

Browse files
Update ty requirement from <0.0.81,>=0.0.8 to >=0.0.8,<0.0.85 (#194)
* Update ty requirement from <0.0.81,>=0.0.8 to >=0.0.8,<0.0.85 Updates the requirements on [ty](https://github.com/astral-sh/ty) to permit the latest version. - [Release notes](https://github.com/astral-sh/ty/releases) - [Changelog](https://github.com/astral-sh/ty/blob/main/CHANGELOG.md) - [Commits](astral-sh/ty@0.0.8...0.0.84) --- updated-dependencies: - dependency-name: ty dependency-version: 0.0.84 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> * Fix typing for updated ty * Handle provisional return products in parallel wrapper --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tobias Raabe <raabe@posteo.de>
1 parent 4dcbce0 commit 1ceb379

4 files changed

Lines changed: 45 additions & 18 deletions

File tree

‎docs/source/conf.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# The version, including alpha/beta/rc tags, but not commit hash and datestamps
3535
release = version("pytask_parallel")
3636
# The short X.Y version.
37-
version = ".".join(release.split(".")[:2]) # ty: ignore[invalid-assignment]
37+
version = ".".join(release.split(".")[:2])
3838

3939
# -- General configuration -------------------------------------------------------------
4040

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test = [
5050
]
5151
typing = [
5252
"pytask-parallel",
53-
"ty>=0.0.8,<0.0.81",
53+
"ty>=0.0.8,<0.0.85",
5454
{include-group = "coiled"},
5555
{include-group = "dask"},
5656
]

‎src/pytask_parallel/wrappers.py‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from attrs import define
1919
from pytask import PNode
2020
from pytask import PPathNode
21+
from pytask import PProvisionalNode
2122
from pytask import PTask
2223
from pytask import PythonNode
2324
from pytask import Traceback
@@ -255,7 +256,7 @@ def _handle_function_products(
255256
raise ValueError(msg)
256257

257258
def _save_and_carry_over_product(
258-
path: tuple[Any, ...], node: PNode
259+
path: tuple[Any, ...], node: PNode | PProvisionalNode
259260
) -> CarryOverPath | PythonNode | None:
260261
argument = path[0]
261262

@@ -275,25 +276,38 @@ def _save_and_carry_over_product(
275276
for p in path[1:]:
276277
value = value[p]
277278

278-
# If the node is a PythonNode, we need to carry it over to the main process.
279-
if isinstance(node, PythonNode):
280-
node.save(value=value)
281-
return node
279+
return _save_return_product(node, value, remote=remote)
282280

283-
# If the path is local and we are remote, we need to carry over the value to
284-
# the main process as a PythonNode and save it later.
285-
if isinstance(node, PPathNode) and is_local_path(node.path) and remote:
286-
return PythonNode(value=value)
281+
return cast(
282+
"PyTree[CarryOverPath | PythonNode | None]",
283+
tree_map_with_path(
284+
_save_and_carry_over_product,
285+
cast("Any", task.produces),
286+
),
287+
)
287288

288-
# If no condition applies, we save the value and do not carry it over. Like a
289-
# remote path to S3.
290-
node.save(value)
289+
290+
def _save_return_product(
291+
node: PNode | PProvisionalNode,
292+
value: Any, # noqa: ANN401
293+
*,
294+
remote: bool,
295+
) -> CarryOverPath | PythonNode | None:
296+
"""Save a concrete return product or defer a provisional one to collection."""
297+
if isinstance(node, PProvisionalNode):
291298
return None
292299

293-
return tree_map_with_path(
294-
_save_and_carry_over_product,
295-
cast("Any", task.produces),
296-
)
300+
# Python nodes must be carried back to the main process.
301+
if isinstance(node, PythonNode):
302+
node.save(value=value)
303+
return node
304+
305+
# Local paths on remote workers are saved by the main process.
306+
if isinstance(node, PPathNode) and is_local_path(node.path) and remote:
307+
return PythonNode(value=value)
308+
309+
node.save(value)
310+
return None
297311

298312

299313
def _write_local_files_to_remote(

‎tests/test_execute.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
from time import time
77

88
import pytest
9+
from pytask import DirectoryNode
910
from pytask import ExitCode
11+
from pytask import TaskWithoutPath
1012
from pytask import build
1113
from pytask import cli
1214

1315
from pytask_parallel import ParallelBackend
1416
from pytask_parallel.execute import _Sleeper
17+
from pytask_parallel.wrappers import _handle_function_products
1518
from tests.conftest import restore_sys_path_and_module_after_test_execution
1619
from tests.conftest import skip_if_deadlock
1720

@@ -28,6 +31,16 @@
2831
]
2932

3033

34+
def test_provisional_return_product_is_not_saved() -> None:
35+
task = TaskWithoutPath(
36+
name="provisional",
37+
function=lambda: None,
38+
produces={"return": DirectoryNode()},
39+
)
40+
41+
assert _handle_function_products(task, None) == {"return": None}
42+
43+
3144
@pytest.mark.parametrize("parallel_backend", _IMPLEMENTED_BACKENDS)
3245
def test_parallel_execution(tmp_path, parallel_backend):
3346
source = """

0 commit comments

Comments
 (0)