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
2 changes: 2 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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}`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

Expand Down
2 changes: 2 additions & 0 deletions src/_pytask/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
27 changes: 12 additions & 15 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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__":
Expand Down