From b72807f65f0ed78d6859516eb4f9621bca3e5b50 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 29 Aug 2023 10:18:40 +0200 Subject: [PATCH 1/2] Do not require .value for Node. --- src/_pytask/node_protocols.py | 2 -- src/_pytask/nodes.py | 14 +++++--------- tests/test_collect_command.py | 6 ++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/_pytask/node_protocols.py b/src/_pytask/node_protocols.py index f6dc2cf09..39e1afb54 100644 --- a/src/_pytask/node_protocols.py +++ b/src/_pytask/node_protocols.py @@ -29,8 +29,6 @@ def state(self) -> str | None: class Node(MetaNode, Protocol): """Protocol for nodes.""" - value: Any - def load(self) -> Any: """Return the value of the node that will be injected into the task.""" ... diff --git a/src/_pytask/nodes.py b/src/_pytask/nodes.py index 8bc550c83..0aa4964db 100644 --- a/src/_pytask/nodes.py +++ b/src/_pytask/nodes.py @@ -106,12 +106,8 @@ class PathNode(Node): name: str = "" """Name of the node which makes it identifiable in the DAG.""" - value: Path | None = None - """Value passed to the decorator which can be requested inside the function.""" - - @property - def path(self) -> Path: - return self.value + path: Path | None = None + """The path to the file.""" def from_annot(self, value: Path) -> None: """Set path and if other attributes are not set, set sensible defaults.""" @@ -119,7 +115,7 @@ def from_annot(self, value: Path) -> None: raise TypeError("'value' must be a 'pathlib.Path'.") if not self.name: self.name = value.as_posix() - self.value = value + self.path = value @classmethod @functools.lru_cache @@ -131,7 +127,7 @@ def from_path(cls, path: Path) -> PathNode: """ if not path.is_absolute(): raise ValueError("Node must be instantiated from absolute path.") - return cls(name=path.as_posix(), value=path) + return cls(name=path.as_posix(), path=path) def state(self) -> str | None: """Calculate the state of the node. @@ -145,7 +141,7 @@ def state(self) -> str | None: def load(self) -> Path: """Load the value.""" - return self.value + return self.path def save(self, value: bytes | str) -> None: """Save strings or bytes to file.""" diff --git a/tests/test_collect_command.py b/tests/test_collect_command.py index 3007221da..c0c16c46b 100644 --- a/tests/test_collect_command.py +++ b/tests/test_collect_command.py @@ -385,10 +385,8 @@ def test_print_collected_tasks_with_nodes(capsys): base_name="function", path=Path("task_path.py"), function=function, - depends_on={ - "depends_on": PathNode(name="in.txt", value=Path("in.txt")) - }, - produces={0: PathNode(name="out.txt", value=Path("out.txt"))}, + depends_on={"depends_on": PathNode(name="in.txt", path=Path("in.txt"))}, + produces={0: PathNode(name="out.txt", path=Path("out.txt"))}, ) ] } From 33fac11f16c6ae13b346c3ed25852ec7c503764c Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 29 Aug 2023 10:21:10 +0200 Subject: [PATCH 2/2] to changes. --- docs/source/changes.md | 1 + src/_pytask/nodes.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 7320f560d..3f6a68716 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -25,6 +25,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and implementing their own nodes. - {pull}`404` allows to use function returns to define task products. - {pull}`405` allows to match function returns to node annotations with prefix trees. +- {pull}`406` removes `.value` from `Node` protocol. ## 0.3.2 - 2023-06-07 diff --git a/src/_pytask/nodes.py b/src/_pytask/nodes.py index 0aa4964db..e4fd9f3f2 100644 --- a/src/_pytask/nodes.py +++ b/src/_pytask/nodes.py @@ -10,6 +10,7 @@ from _pytask.node_protocols import MetaNode from _pytask.node_protocols import Node +from _pytask.node_protocols import PPathNode from _pytask.tree_util import PyTree from _pytask.tree_util import tree_leaves from _pytask.tree_util import tree_structure @@ -101,7 +102,7 @@ def add_report_section(self, when: str, key: str, content: str) -> None: @define(kw_only=True) -class PathNode(Node): +class PathNode(PPathNode): """The class for a node which is a path.""" name: str = ""