Skip to content

Commit 14d82c5

Browse files
committed
Add more warnings:
1 parent 95a9657 commit 14d82c5

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

src/_pytask/collect.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from _pytask.mark import MarkGenerator
3131
from _pytask.mark_utils import get_all_marks
3232
from _pytask.mark_utils import has_mark
33-
from _pytask.node_protocols import PNode
33+
from _pytask.node_protocols import PNode, warn_about_upcoming_attributes_field_on_nodes
3434
from _pytask.node_protocols import PPathNode
3535
from _pytask.node_protocols import PProvisionalNode
3636
from _pytask.node_protocols import PTask
@@ -387,14 +387,7 @@ def pytask_collect_node( # noqa: C901, PLR0912
387387
node = node_info.value
388388

389389
if isinstance(node, (PNode, PProvisionalNode)) and not hasattr(node, "attributes"):
390-
warnings.warn(
391-
"PNode and PProvisionalNode will require an 'attributes' field starting "
392-
"with pytask v0.6.0. It is a dictionary with any type of key and values "
393-
"similar to PTask. See https://tinyurl.com/pytask-custom-nodes for more "
394-
"information about adjusting your custom nodes.",
395-
stacklevel=1,
396-
category=FutureWarning,
397-
)
390+
warn_about_upcoming_attributes_field_on_nodes()
398391

399392
if isinstance(node, DirectoryNode):
400393
if node.root_dir is None:

src/_pytask/console.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import Any
1313
from typing import Callable
1414
from typing import Literal
15+
import warnings
1516

1617
from rich.console import Console
1718
from rich.console import RenderableType
@@ -25,7 +26,7 @@
2526
from rich.tree import Tree
2627

2728
from _pytask.data_catalog_utils import DATA_CATALOG_NAME_FIELD
28-
from _pytask.node_protocols import PNode
29+
from _pytask.node_protocols import PNode, warn_about_upcoming_attributes_field_on_nodes
2930
from _pytask.node_protocols import PPathNode
3031
from _pytask.node_protocols import PProvisionalNode
3132
from _pytask.node_protocols import PTaskWithPath
@@ -148,8 +149,9 @@ def format_node_name(
148149
"""Format the name of a node."""
149150
if isinstance(node, PPathNode):
150151
if node.name != node.path.as_posix():
151-
if data_catalog_name := node.attributes.get(DATA_CATALOG_NAME_FIELD):
152+
if data_catalog_name := getattr(node, "attributes", {}).get(DATA_CATALOG_NAME_FIELD):
152153
return Text(f"{data_catalog_name}::{node.name}")
154+
warn_about_upcoming_attributes_field_on_nodes()
153155
return Text(node.name)
154156
name = shorten_path(node.path, paths)
155157
return Text(name)

src/_pytask/data_catalog.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from _pytask.data_catalog_utils import DATA_CATALOG_NAME_FIELD
2121
from _pytask.exceptions import NodeNotCollectedError
2222
from _pytask.models import NodeInfo
23-
from _pytask.node_protocols import PNode
23+
from _pytask.node_protocols import PNode, warn_about_upcoming_attributes_field_on_nodes
2424
from _pytask.node_protocols import PPathNode
2525
from _pytask.node_protocols import PProvisionalNode
2626
from _pytask.nodes import PickleNode
@@ -139,4 +139,9 @@ def add(self, name: str, node: PNode | PProvisionalNode | Any = None) -> None:
139139
msg = f"{node!r} cannot be parsed."
140140
raise NodeNotCollectedError(msg)
141141
self._entries[name] = collected_node
142-
self._entries[name].attributes[DATA_CATALOG_NAME_FIELD] = self.name
142+
143+
node = self._entries[name]
144+
if hasattr(node, "attributes"):
145+
node.attributes[DATA_CATALOG_NAME_FIELD] = self.name
146+
else:
147+
warn_about_upcoming_attributes_field_on_nodes()

src/_pytask/node_protocols.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Callable
66
from typing import Protocol
77
from typing import runtime_checkable
8+
import warnings
89

910
if TYPE_CHECKING:
1011
from pathlib import Path
@@ -138,3 +139,14 @@ def load(self, is_product: bool = False) -> Any: # pragma: no cover
138139

139140
def collect(self) -> list[Any]:
140141
"""Collect the objects that are defined by the provisional nodes."""
142+
143+
144+
def warn_about_upcoming_attributes_field_on_nodes() -> None:
145+
warnings.warn(
146+
"PNode and PProvisionalNode will require an 'attributes' field starting "
147+
"with pytask v0.6.0. It is a dictionary with any type of key and values "
148+
"similar to PTask. See https://tinyurl.com/pytask-custom-nodes for more "
149+
"information about adjusting your custom nodes.",
150+
stacklevel=1,
151+
category=FutureWarning,
152+
)

0 commit comments

Comments
 (0)