Skip to content

Commit 1f2c458

Browse files
authored
Remove @pytask.mark.task and switch to @task. (#552)
1 parent 95f5f1d commit 1f2c458

File tree

14 files changed

+32
-117
lines changed

14 files changed

+32
-117
lines changed

docs/source/_static/md/markers.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ $ pytask markers
2929
│ pytask.mark.skipif │ Skip a task and all its dependent tasks │
3030
│ │ if a condition is met. │
3131
│ │ │
32-
│ pytask.mark.task │ Mark a function as a task regardless of │
33-
│ │ its name. Or mark tasks which are │
34-
│ │ repeated in a loop. See this tutorial │
35-
│ │ for more information: │
36-
│ │ <a href="https://bit.ly/3DWrXS3">https://bit.ly/3DWrXS3</a>. │
37-
│ │ │
3832
│ pytask.mark.try_first │ Try to execute a task a early as │
3933
│ │ possible. │
4034
│ │ │

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
1111
{meth}`~pytask.TaskWithoutPath.execute`. Thanks to {user}`Ostheer`.
1212
- {pull}`551` removes the deprecated `@pytask.mark.depends_on` and
1313
`@pytask.mark.produces`.
14+
- {pull}`552` removes the deprecated `@pytask.mark.task`.
1415

1516
## 0.4.5 - 2024-01-09
1617

docs/source/reference_guides/api.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,6 @@ plugins process. The following marks are available by default.
9696
9797
Skip a task.
9898
99-
.. function:: pytask.mark.task(name, *, id, kwargs)
100-
101-
The task decorator allows to mark any task function regardless of its name as a task
102-
or assigns a new task name.
103-
104-
It also allows to repeat tasks in for-loops by adding a specific ``id`` or keyword
105-
arguments via ``kwargs``.
106-
107-
.. deprecated:: 0.4.0
108-
109-
Will be removed in v0.5.0. Use :func:`~pytask.task` instead.
110-
111-
:type name: str | None
112-
:param name: The name of the task.
113-
:type id: str | None
114-
:param id: An id for the task if it is part of a parametrization.
115-
:type kwargs: dict[Any, Any] | None
116-
:param kwargs:
117-
A dictionary containing keyword arguments which are passed to the task when it
118-
is executed.
119-
12099
.. function:: pytask.mark.try_first
121100
122101
Indicate that the task should be executed as soon as possible.

docs/source/tutorials/write_a_task.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ def create_random_data():
129129
...
130130
```
131131

132-
```{warning}
133-
Since v0.4 users should use {func}`@task <pytask.task>` over
134-
{func}`@pytask.mark.task <pytask.mark.task>` which will be removed in v0.5.
135-
```
136-
137132
## Customize task module names
138133

139134
Use the configuration value {confval}`task_files` if you prefer a different naming

src/_pytask/collect_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ def parse_dependencies_from_task_function(
7070
kwargs[name] = parameters_with_node_annot.pop(name)
7171
else:
7272
msg = (
73-
f"The value for the parameter {name!r} is defined twice in "
74-
"'@pytask.mark.task(kwargs=...)' and in the type annotation. Choose "
75-
"only one option."
73+
f"The value for the parameter {name!r} is defined twice, in "
74+
"'@task(kwargs=...)' and in the type annotation. Choose only one way."
7675
)
7776
raise ValueError(msg)
7877

@@ -209,9 +208,9 @@ def parse_products_from_task_function(
209208
and parameter_name in parameters_with_node_annot
210209
):
211210
msg = (
212-
f"The value for the parameter {parameter_name!r} is defined twice "
213-
"in '@pytask.mark.task(kwargs=...)' and in the type annotation. "
214-
"Choose only one option."
211+
f"The value for the parameter {parameter_name!r} is defined twice, "
212+
"in '@task(kwargs=...)' and in the type annotation. Choose only "
213+
"one way."
215214
)
216215
raise ValueError(msg)
217216

src/_pytask/mark/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def from_task(cls, task: PTask) -> KeywordMatcher:
133133
mapped_names = {task.name}
134134

135135
# Add the names attached to the current function through direct assignment.
136-
function_obj = task.function
137-
if function_obj:
138-
mapped_names.update(function_obj.__dict__)
136+
mapped_names.update(task.function.__dict__)
139137

140138
# Add the markers to the keywords as we no longer handle them correctly.
141139
mapped_names.update(mark.name for mark in task.markers)
@@ -149,7 +147,7 @@ def __call__(self, subname: str) -> bool:
149147
return any(subname in name for name in names)
150148

151149

152-
def select_by_keyword(session: Session, dag: nx.DiGraph) -> set[str]:
150+
def select_by_keyword(session: Session, dag: nx.DiGraph) -> set[str] | None:
153151
"""Deselect tests by keywords."""
154152
keywordexpr = session.config["expression"]
155153
if not keywordexpr:
@@ -204,7 +202,7 @@ def __call__(self, name: str) -> bool:
204202
return name in self.own_mark_names
205203

206204

207-
def select_by_mark(session: Session, dag: nx.DiGraph) -> set[str]:
205+
def select_by_mark(session: Session, dag: nx.DiGraph) -> set[str] | None:
208206
"""Deselect tests by marks."""
209207
matchexpr = session.config["marker_expression"]
210208
if not matchexpr:

src/_pytask/mark/__init__.pyi

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/_pytask/mark/structures.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ def __getattr__(self, name: str) -> MarkDecorator | Any:
196196
if name in ("depends_on", "produces"):
197197
raise RuntimeError(_DEPRECATION_DECORATOR.format(name))
198198

199+
if name == "task":
200+
msg = (
201+
"'@pytask.mark.task' is removed. Use '@task' with 'from pytask import "
202+
"task' instead."
203+
)
204+
raise RuntimeError(msg)
205+
199206
# If the name is not in the set of known marks after updating,
200207
# then it really is time to issue a warning or an error.
201208
if self.config is not None and name not in self.config["markers"]:
@@ -217,19 +224,6 @@ def __getattr__(self, name: str) -> MarkDecorator | Any:
217224
stacklevel=2,
218225
)
219226

220-
if name == "task":
221-
from _pytask.task_utils import task
222-
223-
warnings.warn(
224-
"'@pytask.mark.task' is deprecated starting pytask v0.4.0 and will be "
225-
"removed in v0.5.0. Use '@task' with 'from pytask import task' "
226-
"instead.",
227-
category=FutureWarning,
228-
stacklevel=1,
229-
)
230-
231-
return task
232-
233227
return MarkDecorator(Mark(name, (), {}))
234228

235229

src/_pytask/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Contain hooks related to the ``@pytask.mark.task`` decorator."""
1+
"""Contain hooks related to the :func:`@task <pytask.task>`."""
22
from __future__ import annotations
33

44
from typing import Any

src/_pytask/task_utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Contains utilities related to the ``@pytask.mark.task`` decorator."""
1+
"""Contains utilities related to the :func:`@task <pytask.task>`."""
22
from __future__ import annotations
33

44
import functools
@@ -31,9 +31,9 @@
3131
COLLECTED_TASKS: dict[Path | None, list[Callable[..., Any]]] = defaultdict(list)
3232
"""A container for collecting tasks.
3333
34-
Tasks marked by the ``@pytask.mark.task`` decorator can be generated in a loop where one
35-
iteration overwrites the previous task. To retrieve the tasks later, use this dictionary
36-
mapping from paths of modules to a list of tasks per module.
34+
Tasks marked by the :func:`@task <pytask.task>` decorator can be generated in a loop
35+
where one iteration overwrites the previous task. To retrieve the tasks later, use this
36+
dictionary mapping from paths of modules to a list of tasks per module.
3737
3838
"""
3939

@@ -96,8 +96,7 @@ def wrapper(func: Callable[..., Any]) -> Callable[..., Any]:
9696
for arg, arg_name in ((name, "name"), (id, "id")):
9797
if not (isinstance(arg, str) or arg is None):
9898
msg = (
99-
f"Argument {arg_name!r} of @pytask.mark.task must be a str, but it "
100-
f"is {arg!r}."
99+
f"Argument {arg_name!r} of @task must be a str, but it is {arg!r}."
101100
)
102101
raise ValueError(msg)
103102

@@ -231,7 +230,7 @@ def _parse_task(task: Callable[..., Any]) -> tuple[str, Callable[..., Any]]:
231230

232231
if meta.name is None and task.__name__ == "_":
233232
msg = (
234-
"A task function either needs 'name' passed by the ``@pytask.mark.task`` "
233+
"A task function either needs 'name' passed by the ``@task`` "
235234
"decorator or the function name of the task function must not be '_'."
236235
)
237236
raise ValueError(msg)
@@ -255,7 +254,7 @@ def _parse_task_kwargs(kwargs: Any) -> dict[str, Any]:
255254
if attrs.has(type(kwargs)):
256255
return attrs.asdict(kwargs)
257256
msg = (
258-
"'@pytask.mark.task(kwargs=...) needs to be a dictionary, namedtuple or an "
257+
"'@task(kwargs=...) needs to be a dictionary, namedtuple or an "
259258
"instance of an attrs class."
260259
)
261260
raise ValueError(msg)

0 commit comments

Comments
 (0)