Skip to content

Commit f24b012

Browse files
authored
Remove MetaNode. (#501)
1 parent ee10f9a commit f24b012

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

docs/source/changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
137137
- {pull}`376` enhances the documentation for `pytask dag`.
138138
- {pull}`378` conditionally skips test on MacOS.
139139
- {pull}`381` deprecates `@pytask.mark.parametrize`. (Closes {issue}`233`.)
140+
- {pull}`501` removes {class}`pytask.MetaNode`.
140141

141142
## 0.3.1 - 2023-12-25
142143

docs/source/reference_guides/api.md

-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ The remaining exceptions convey specific errors.
245245
Protocols define how tasks and nodes for dependencies and products have to be set up.
246246

247247
```{eval-rst}
248-
.. autoprotocol:: pytask.MetaNode
249-
:show-inheritance:
250248
.. autoprotocol:: pytask.PNode
251249
:show-inheritance:
252250
.. autoprotocol:: pytask.PPathNode

src/_pytask/database_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sqlalchemy.orm import sessionmaker
1212

1313
if TYPE_CHECKING:
14-
from _pytask.node_protocols import MetaNode
14+
from _pytask.node_protocols import PNode
1515
from _pytask.node_protocols import PTask
1616
from _pytask.session import Session
1717

@@ -66,7 +66,7 @@ def update_states_in_database(session: Session, task_signature: str) -> None:
6666
_create_or_update_state(task_signature, node.signature, hash_)
6767

6868

69-
def has_node_changed(task: PTask, node: MetaNode) -> bool:
69+
def has_node_changed(task: PTask, node: PTask | PNode) -> bool:
7070
"""Indicate whether a single dependency or product has changed."""
7171
# If node does not exist, we receive None.
7272
node_state = node.state()

src/_pytask/node_protocols.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
from _pytask.mark import Mark
1515

1616

17-
__all__ = ["MetaNode", "PNode", "PPathNode", "PTask", "PTaskWithPath"]
17+
__all__ = ["PNode", "PPathNode", "PTask", "PTaskWithPath"]
1818

1919

2020
@runtime_checkable
21-
class MetaNode(Protocol):
22-
"""Protocol for an intersection between nodes and tasks."""
21+
class PNode(Protocol):
22+
"""Protocol for nodes."""
2323

2424
name: str
2525

2626
@property
2727
def signature(self) -> str:
2828
"""Return the signature of the node."""
29-
...
3029

3130
@abstractmethod
3231
def state(self) -> str | None:
@@ -36,12 +35,6 @@ def state(self) -> str | None:
3635
does not exist, you can also return ``None``.
3736
3837
"""
39-
...
40-
41-
42-
@runtime_checkable
43-
class PNode(MetaNode, Protocol):
44-
"""Protocol for nodes."""
4538

4639
def load(self, is_product: bool) -> Any:
4740
"""Return the value of the node that will be injected into the task.
@@ -55,11 +48,9 @@ def load(self, is_product: bool) -> Any:
5548
user calling :meth:`PNode.load`.
5649
5750
"""
58-
...
5951

6052
def save(self, value: Any) -> Any:
6153
"""Save the value that was returned from a task."""
62-
...
6354

6455

6556
@runtime_checkable
@@ -74,19 +65,32 @@ class PPathNode(PNode, Protocol):
7465

7566

7667
@runtime_checkable
77-
class PTask(MetaNode, Protocol):
68+
class PTask(Protocol):
7869
"""Protocol for nodes."""
7970

71+
name: str
8072
depends_on: dict[str, PyTree[PNode]]
8173
produces: dict[str, PyTree[PNode]]
74+
function: Callable[..., Any]
8275
markers: list[Mark]
8376
report_sections: list[tuple[str, str, str]]
8477
attributes: dict[Any, Any]
85-
function: Callable[..., Any]
78+
79+
@property
80+
def signature(self) -> str:
81+
"""Return the signature of the node."""
82+
83+
@abstractmethod
84+
def state(self) -> str | None:
85+
"""Return the state of the node.
86+
87+
The state can be something like a hash or a last modified timestamp. If the node
88+
does not exist, you can also return ``None``.
89+
90+
"""
8691

8792
def execute(self, **kwargs: Any) -> Any:
8893
"""Return the value of the node that will be injected into the task."""
89-
...
9094

9195

9296
@runtime_checkable

src/_pytask/reports.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@
1717

1818

1919
if TYPE_CHECKING:
20+
from _pytask.node_protocols import PNode
2021
from _pytask.node_protocols import PTask
2122
from rich.console import Console
2223
from rich.console import RenderResult
2324
from rich.console import ConsoleOptions
24-
from _pytask.node_protocols import MetaNode
2525

2626

2727
@define
2828
class CollectionReport:
2929
"""A collection report for a task."""
3030

3131
outcome: CollectionOutcome
32-
node: MetaNode | None = None
32+
node: PTask | PNode | None = None
3333
exc_info: OptionalExceptionInfo | None = None
3434

3535
@classmethod
3636
def from_exception(
3737
cls: type[CollectionReport],
3838
outcome: CollectionOutcome,
3939
exc_info: OptionalExceptionInfo,
40-
node: MetaNode | None = None,
40+
node: PTask | PNode | None = None,
4141
) -> CollectionReport:
4242
return cls(outcome=outcome, node=node, exc_info=exc_info)
4343

src/pytask/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from _pytask.mark_utils import set_marks
4040
from _pytask.models import CollectionMetadata
4141
from _pytask.models import NodeInfo
42-
from _pytask.node_protocols import MetaNode
4342
from _pytask.node_protocols import PNode
4443
from _pytask.node_protocols import PPathNode
4544
from _pytask.node_protocols import PTask
@@ -97,7 +96,6 @@
9796
"Mark",
9897
"MarkDecorator",
9998
"MarkGenerator",
100-
"MetaNode",
10199
"NodeInfo",
102100
"NodeNotCollectedError",
103101
"NodeNotFoundError",

0 commit comments

Comments
 (0)