Skip to content
Open
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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and

## Unreleased

- Nothing yet.
- Removed the direct dependency on attrs and migrated internal models to dataclasses.

## 0.5.8 - 2025-12-30

Expand Down
1 change: 1 addition & 0 deletions docs/source/reference_guides/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Nodes are the interface for different kinds of dependencies or products.
:members:
.. autoclass:: pytask.PickleNode
:members:
:exclude-members: serializer, deserializer
.. autoclass:: pytask.PythonNode
:members:
.. autoclass:: pytask.DirectoryNode
Expand Down
4 changes: 2 additions & 2 deletions docs_src/how_to_guides/the_data_catalog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any

import cloudpickle
from attrs import define


@define
@dataclass
class PickleNode:
"""A node for pickle files.

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"attrs>=21.3.0",
"click>=8.1.8,!=8.2.0",
"click-default-group>=1.2.4",
"networkx>=2.4.0",
Expand Down
15 changes: 7 additions & 8 deletions src/_pytask/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import functools
import hashlib
import inspect
from dataclasses import dataclass
from dataclasses import field
from inspect import FullArgSpec
from typing import TYPE_CHECKING
from typing import Any
from typing import ParamSpec
from typing import Protocol
from typing import TypeVar

from attrs import define
from attrs import field

from _pytask._hashlib import hash_value

if TYPE_CHECKING:
Expand All @@ -35,17 +34,17 @@ class HasCache(Protocol):
cache: Cache


@define
@dataclass
class CacheInfo:
hits: int = 0
misses: int = 0


@define
@dataclass
class Cache:
_cache: dict[str, Any] = field(factory=dict)
_sentinel: Any = field(factory=object)
cache_info: CacheInfo = field(factory=CacheInfo)
_cache: dict[str, Any] = field(default_factory=dict)
_sentinel: Any = field(default_factory=object)
cache_info: CacheInfo = field(default_factory=CacheInfo)

def memoize(self, func: Callable[P, R]) -> Memoized[P, R]:
func_module = getattr(func, "__module__", "")
Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import itertools
import shutil
import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import Any

import click
from attrs import define

from _pytask.click import ColoredCommand
from _pytask.click import EnumChoice
Expand Down Expand Up @@ -243,7 +243,7 @@ def _find_all_unknown_paths(
)


@define(repr=False)
@dataclass(repr=False)
class _RecursivePathNode:
"""A class for a path to a file or directory which recursively instantiates itself.

Expand Down
5 changes: 2 additions & 3 deletions src/_pytask/coiled_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import Any

from attrs import define

if TYPE_CHECKING:
from collections.abc import Callable

try:
from coiled.function import Function
except ImportError:

@define
@dataclass
class Function:
cluster_kwargs: dict[str, Any]
environ: dict[str, Any]
Expand Down
5 changes: 2 additions & 3 deletions src/_pytask/collect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from __future__ import annotations

import inspect
from dataclasses import replace
from typing import TYPE_CHECKING
from typing import Annotated
from typing import Any
from typing import get_origin

import attrs

from _pytask._inspect import get_annotations
from _pytask.exceptions import NodeNotCollectedError
from _pytask.models import NodeInfo
Expand Down Expand Up @@ -308,7 +307,7 @@ def collect_dependency(
# If a node is a dependency and its value is not set, the node is a product in
# another task and the value will be set there. Thus, we wrap the original node
# in another node to retrieve the value after it is set.
new_node = attrs.evolve(node, value=node)
new_node = replace(node, value=node)
node_info = node_info._replace(value=new_node)

collected_node = session.hook.pytask_collect_node(
Expand Down
12 changes: 6 additions & 6 deletions src/_pytask/dag_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from __future__ import annotations

import itertools
from dataclasses import dataclass
from dataclasses import field
from typing import TYPE_CHECKING

import networkx as nx
from attrs import define
from attrs import field

from _pytask.mark_utils import has_mark

Expand Down Expand Up @@ -61,7 +61,7 @@ def node_and_neighbors(dag: nx.DiGraph, node: str) -> Iterable[str]:
return itertools.chain(dag.predecessors(node), [node], dag.successors(node))


@define
@dataclass
class TopologicalSorter:
"""The topological sorter class.

Expand All @@ -78,9 +78,9 @@ class TopologicalSorter:
"""

dag: nx.DiGraph
priorities: dict[str, int] = field(factory=dict)
_nodes_processing: set[str] = field(factory=set)
_nodes_done: set[str] = field(factory=set)
priorities: dict[str, int] = field(default_factory=dict)
_nodes_processing: set[str] = field(default_factory=set)
_nodes_done: set[str] = field(default_factory=set)

@classmethod
def from_dag(cls, dag: nx.DiGraph) -> TopologicalSorter:
Expand Down
11 changes: 9 additions & 2 deletions src/_pytask/data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from _pytask.exceptions import NodeNotCollectedError
from _pytask.models import NodeInfo
from _pytask.node_protocols import PNode
from _pytask.node_protocols import PPathNode
from _pytask.node_protocols import PProvisionalNode
from _pytask.node_protocols import warn_about_upcoming_attributes_field_on_nodes
from _pytask.nodes import PickleNode
Expand All @@ -39,6 +38,14 @@ def _get_parent_path_of_data_catalog_module(stacklevel: int = 2) -> Path:
return Path.cwd()


def _is_path_node_type(node_type: type[Any]) -> bool:
"""Return True if the class looks like a path-based node."""
for cls in node_type.__mro__:
if "path" in getattr(cls, "__annotations__", {}):
return True
return False


@dataclass(kw_only=True)
class DataCatalog:
"""A data catalog.
Expand Down Expand Up @@ -115,7 +122,7 @@ def add(self, name: str, node: PNode | PProvisionalNode | Any = None) -> None:

if node is None:
filename = hashlib.sha256(name.encode()).hexdigest()
if isinstance(self.default_node, PPathNode):
if _is_path_node_type(self.default_node):
assert self.path is not None
self._entries[name] = self.default_node(
name=name, path=self.path / f"{filename}.pkl"
Expand Down
12 changes: 6 additions & 6 deletions src/_pytask/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
from typing import TYPE_CHECKING
from typing import Any
from typing import Literal

from attrs import define
from attrs import field
from rich.text import Text

from _pytask.console import console
Expand All @@ -34,14 +34,14 @@
]


@define
@dataclass
class ChangeReason:
"""Represents a reason why a node changed."""

node_name: str
node_type: NodeType
reason: ReasonType
details: dict[str, Any] = field(factory=dict)
details: dict[str, Any] = field(default_factory=dict)
verbose: int = 1

def __rich_console__(
Expand Down Expand Up @@ -71,11 +71,11 @@ def __rich_console__(
yield Text(f" • {self.node_name}: {self.reason}")


@define
@dataclass
class TaskExplanation:
"""Represents the explanation for why a task needs to be executed."""

reasons: list[ChangeReason] = field(factory=list)
reasons: list[ChangeReason] = field(default_factory=list)
task: PTask | None = None
outcome: TaskOutcome | None = None
verbose: int = 1
Expand Down
17 changes: 9 additions & 8 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
from typing import TYPE_CHECKING
from typing import Any
from typing import NamedTuple

import click
from attrs import define
from attrs import field
from rich.box import ROUNDED
from rich.errors import LiveError
from rich.live import Live
Expand Down Expand Up @@ -85,7 +84,7 @@ def pytask_execute(session: Session) -> Generator[None, None, None]:
return (yield)


@define(eq=False)
@dataclass(eq=False)
class LiveManager:
"""A class for live displays during a session.

Expand All @@ -106,7 +105,9 @@ class LiveManager:
"""

_live: Live = field(
factory=lambda: Live(renderable=None, console=console, auto_refresh=False)
default_factory=lambda: Live(
renderable=None, console=console, auto_refresh=False
)
)

def start(self) -> None:
Expand Down Expand Up @@ -157,7 +158,7 @@ class _ReportEntry(NamedTuple):
task: PTask


@define(eq=False, kw_only=True)
@dataclass(eq=False, kw_only=True)
class LiveExecution:
"""A class for managing the table displaying task progress during the execution."""

Expand All @@ -168,8 +169,8 @@ class LiveExecution:
initial_status: TaskExecutionStatus = TaskExecutionStatus.RUNNING
sort_final_table: bool = False
n_tasks: int | str = "x"
_reports: list[_ReportEntry] = field(factory=list)
_running_tasks: dict[str, _TaskEntry] = field(factory=dict)
_reports: list[_ReportEntry] = field(default_factory=list)
_running_tasks: dict[str, _TaskEntry] = field(default_factory=dict)

@hookimpl(wrapper=True)
def pytask_execute_build(self) -> Generator[None, None, None]:
Expand Down Expand Up @@ -306,7 +307,7 @@ def update_report(self, new_report: ExecutionReport) -> None:
self._update_table()


@define(eq=False, kw_only=True)
@dataclass(eq=False, kw_only=True)
class LiveCollection:
"""A class for managing the live status during the collection."""

Expand Down
1 change: 1 addition & 0 deletions src/_pytask/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def pytask_log_session_header(session: Session) -> None:
f"Platform: {sys.platform} -- Python {platform.python_version()}, "
f"pytask {_pytask.__version__}, pluggy {pluggy.__version__}",
highlight=False,
soft_wrap=True,
)
console.print(f"Root: {session.config['root']}")
if session.config["config"] is not None:
Expand Down
6 changes: 3 additions & 3 deletions src/_pytask/mark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from __future__ import annotations

import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import Any

import click
from attrs import define
from rich.table import Table

from _pytask.click import ColoredCommand
Expand Down Expand Up @@ -117,7 +117,7 @@ def pytask_post_parse(config: dict[str, Any]) -> None:
config["markers"] = parse_markers(config["markers"])


@define(slots=True)
@dataclass(slots=True)
class KeywordMatcher:
"""A matcher for keywords.

Expand Down Expand Up @@ -189,7 +189,7 @@ def select_by_after_keyword(session: Session, after: str) -> set[str]:
return ancestors


@define(slots=True)
@dataclass(slots=True)
class MarkMatcher:
"""A matcher for markers which are present.

Expand Down
5 changes: 2 additions & 3 deletions src/_pytask/mark/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
from collections.abc import Iterator
from collections.abc import Mapping
from collections.abc import Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING

from attrs import define

if TYPE_CHECKING:
import types
from typing import NoReturn
Expand All @@ -53,7 +52,7 @@ class TokenType(enum.Enum):
EOF = "end of input"


@define(frozen=True, slots=True)
@dataclass(frozen=True, slots=True)
class Token:
type_: TokenType
value: str
Expand Down
Loading