Skip to content

Commit 60201c4

Browse files
authored
Deprecate @pytask.mark.task in favor of @pytask.task. (#417)
1 parent a00c62d commit 60201c4

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
3434
- {pull}`413` removes scripts to generate `.svg`s.
3535
- {pull}`414` allow more ruff rules.
3636
- {pull}`416` removes `.from_annot` again.
37+
- {pull}`417` deprecates {func}`pytask.mark.task` in favor of {func}`pytask.task`.
3738

3839
## 0.3.2 - 2023-06-07
3940

src/_pytask/mark/__init__.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from typing import Any
23
from typing_extensions import deprecated
34
from _pytask.mark.expression import Expression
45
from _pytask.mark.expression import ParseError
@@ -28,6 +29,19 @@ class MARK_GEN: # noqa: N801
2829
)
2930
@staticmethod
3031
def depends_on(objects: PyTree[str | Path]) -> None: ...
32+
@deprecated(
33+
"'@pytask.mark.task' is deprecated starting pytask v0.4.0 and will be removed in v0.5.0. Use '@pytask.task' instead.", # noqa: E501, PYI053
34+
category=DeprecationWarning,
35+
stacklevel=1,
36+
)
37+
@staticmethod
38+
def task(
39+
name: str | None = None,
40+
*,
41+
id: str | None = None, # noqa: A002
42+
kwargs: dict[Any, Any] | None = None,
43+
produces: PyTree[Any] = None,
44+
) -> None: ...
3145

3246
__all__ = [
3347
"Expression",

src/_pytask/mark/structures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ def __getattr__(self, name: str) -> MarkDecorator | Any:
230230
if name == "task":
231231
from _pytask.task_utils import task
232232

233+
warnings.warn(
234+
"'@pytask.mark.task' is deprecated starting pytask v0.4.0 and will be "
235+
"removed in v0.5.0. Use '@pytask.task' instead.",
236+
category=DeprecationWarning,
237+
stacklevel=1,
238+
)
239+
233240
return task
234241

235242
return MarkDecorator(Mark(name, (), {}))

src/pytask/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from _pytask.report import DagReport
5959
from _pytask.report import ExecutionReport
6060
from _pytask.session import Session
61+
from _pytask.task_utils import task
6162
from _pytask.traceback import format_exception_without_traceback
6263
from _pytask.traceback import remove_internal_traceback_frames_from_exc_info
6364
from _pytask.traceback import remove_traceback_from_exc_info
@@ -139,5 +140,6 @@
139140
"remove_traceback_from_exc_info",
140141
"render_exc_info",
141142
"set_marks",
143+
"task",
142144
"warning_record_to_str",
143145
]

tests/test_mark.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,21 @@ def task_write_text(depends_on, produces):
377377
)
378378
assert b"DeprecationWarning: '@pytask.mark.depends_on'" in result.stdout
379379
assert b"DeprecationWarning: '@pytask.mark.produces'" in result.stdout
380+
381+
382+
@pytest.mark.end_to_end()
383+
def test_deprecation_warnings_for_task_decorator(tmp_path):
384+
source = """
385+
import pytask
386+
387+
@pytask.mark.task
388+
def task_write_text(): ...
389+
"""
390+
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
391+
392+
result = subprocess.run(
393+
("pytest", tmp_path.joinpath("task_module.py").as_posix()),
394+
capture_output=True,
395+
check=False,
396+
)
397+
assert b"DeprecationWarning: '@pytask.mark.task'" in result.stdout

0 commit comments

Comments
 (0)