From 37f3b0c389ad0349f6207c9c354ad2e2521cb48a Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 9 Apr 2024 10:06:53 +0200 Subject: [PATCH 1/3] Recreate PythonNodes every run. --- docs/source/changes.md | 1 + src/_pytask/nodes.py | 2 ++ tests/test_execute.py | 27 ++++++++++++--------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 5762765c9..89187e3d4 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -35,6 +35,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`591` invalidates the cache of fsspec when checking whether a remote file exists. Otherwise, a remote file might be reported as missing although it was just created. See https://github.com/fsspec/s3fs/issues/851 for more info. +- {pull}`592` makes `PythonNode`s state `None` if they carry the `_NoDefault` enum. ## 0.4.7 - 2024-03-19 diff --git a/src/_pytask/nodes.py b/src/_pytask/nodes.py index 9133eebba..24b4d2072 100644 --- a/src/_pytask/nodes.py +++ b/src/_pytask/nodes.py @@ -280,6 +280,8 @@ def state(self) -> str | None: {meth}`object.__hash__` for more information. """ + if self.value is no_default: + return None if self.hash: value = self.load() if callable(self.hash): diff --git a/tests/test_execute.py b/tests/test_execute.py index 8459914a5..e74b5dc24 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -519,6 +519,12 @@ def task_example() -> Annotated[Dict[str, str], PythonNode(name="result")]: tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) result = runner.invoke(cli, [tmp_path.as_posix()]) assert result.exit_code == ExitCode.OK + assert "1 Succeeded" in result.output + + # Test that python nodes are recreated every run. + result = runner.invoke(cli, [tmp_path.as_posix()]) + assert result.exit_code == ExitCode.OK + assert "1 Succeeded" in result.output @pytest.mark.end_to_end() @@ -544,10 +550,6 @@ def task_example() -> Annotated[Dict[str, str], nodes]: assert result.exit_code == ExitCode.OK assert "1 Succeeded" in result.output - result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == ExitCode.OK - assert "1 Skipped" in result.output - @pytest.mark.end_to_end() def test_more_nested_pytree_and_python_node_as_return(runner, tmp_path): @@ -568,15 +570,10 @@ def task_example() -> Annotated[Dict[str, str], nodes]: assert result.exit_code == ExitCode.OK assert "1 Succeeded" in result.output - result = runner.invoke(cli, [tmp_path.as_posix()]) - assert result.exit_code == ExitCode.OK - assert "1 Skipped" in result.output - @pytest.mark.end_to_end() def test_execute_tasks_and_pass_values_only_by_python_nodes(runner, tmp_path): source = """ - from pytask import PathNode from pytask import PythonNode from typing_extensions import Annotated from pathlib import Path @@ -586,9 +583,9 @@ def test_execute_tasks_and_pass_values_only_by_python_nodes(runner, tmp_path): def task_create_text() -> Annotated[int, node_text]: return "This is the text." - node_file = PathNode(path=Path("file.txt")) - - def task_create_file(text: Annotated[int, node_text]) -> Annotated[str, node_file]: + def task_create_file( + text: Annotated[int, node_text] + ) -> Annotated[str, Path("file.txt")]: return text """ tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source)) @@ -611,9 +608,9 @@ def test_execute_tasks_via_functional_api(tmp_path): def create_text() -> Annotated[int, node_text]: return "This is the text." - node_file = PathNode(path=Path("file.txt")) - - def create_file(content: Annotated[str, node_text]) -> Annotated[str, node_file]: + def create_file( + content: Annotated[str, node_text] + ) -> Annotated[str, Path("file.txt")]: return content if __name__ == "__main__": From 25589bc2cabea675a5ae14170b1390faed53a2ea Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 9 Apr 2024 10:08:10 +0200 Subject: [PATCH 2/3] addition. --- docs/source/changes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 89187e3d4..c4f5b69ed 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -35,7 +35,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`591` invalidates the cache of fsspec when checking whether a remote file exists. Otherwise, a remote file might be reported as missing although it was just created. See https://github.com/fsspec/s3fs/issues/851 for more info. -- {pull}`592` makes `PythonNode`s state `None` if they carry the `_NoDefault` enum. +- {pull}`592` recreate `PythonNode`s every run since they carry the `_NoDefault` enum as + the value whose state is `None`. ## 0.4.7 - 2024-03-19 From 40ffbd5a9e20c88ae1b73ff00a95f1d5ee1a3479 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 9 Apr 2024 12:07:31 +0200 Subject: [PATCH 3/3] Fix changes. --- docs/source/changes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index c4f5b69ed..4b81e0fb2 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -35,7 +35,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`591` invalidates the cache of fsspec when checking whether a remote file exists. Otherwise, a remote file might be reported as missing although it was just created. See https://github.com/fsspec/s3fs/issues/851 for more info. -- {pull}`592` recreate `PythonNode`s every run since they carry the `_NoDefault` enum as +- {pull}`593` recreate `PythonNode`s every run since they carry the `_NoDefault` enum as the value whose state is `None`. ## 0.4.7 - 2024-03-19