Skip to content

Deprecate @pytask.mark.task in favor of @pytask.task. #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2023
Merged
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
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`413` removes scripts to generate `.svg`s.
- {pull}`414` allow more ruff rules.
- {pull}`416` removes `.from_annot` again.
- {pull}`417` deprecates {func}`pytask.mark.task` in favor of {func}`pytask.task`.

## 0.3.2 - 2023-06-07

Expand Down
14 changes: 14 additions & 0 deletions src/_pytask/mark/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Any
from typing_extensions import deprecated
from _pytask.mark.expression import Expression
from _pytask.mark.expression import ParseError
Expand Down Expand Up @@ -28,6 +29,19 @@ class MARK_GEN: # noqa: N801
)
@staticmethod
def depends_on(objects: PyTree[str | Path]) -> None: ...
@deprecated(
"'@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
category=DeprecationWarning,
stacklevel=1,
)
@staticmethod
def task(
name: str | None = None,
*,
id: str | None = None, # noqa: A002
kwargs: dict[Any, Any] | None = None,
produces: PyTree[Any] = None,
) -> None: ...

__all__ = [
"Expression",
Expand Down
7 changes: 7 additions & 0 deletions src/_pytask/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ def __getattr__(self, name: str) -> MarkDecorator | Any:
if name == "task":
from _pytask.task_utils import task

warnings.warn(
"'@pytask.mark.task' is deprecated starting pytask v0.4.0 and will be "
"removed in v0.5.0. Use '@pytask.task' instead.",
category=DeprecationWarning,
stacklevel=1,
)

return task

return MarkDecorator(Mark(name, (), {}))
Expand Down
2 changes: 2 additions & 0 deletions src/pytask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from _pytask.report import DagReport
from _pytask.report import ExecutionReport
from _pytask.session import Session
from _pytask.task_utils import task
from _pytask.traceback import format_exception_without_traceback
from _pytask.traceback import remove_internal_traceback_frames_from_exc_info
from _pytask.traceback import remove_traceback_from_exc_info
Expand Down Expand Up @@ -139,5 +140,6 @@
"remove_traceback_from_exc_info",
"render_exc_info",
"set_marks",
"task",
"warning_record_to_str",
]
18 changes: 18 additions & 0 deletions tests/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,21 @@ def task_write_text(depends_on, produces):
)
assert b"DeprecationWarning: '@pytask.mark.depends_on'" in result.stdout
assert b"DeprecationWarning: '@pytask.mark.produces'" in result.stdout


@pytest.mark.end_to_end()
def test_deprecation_warnings_for_task_decorator(tmp_path):
source = """
import pytask

@pytask.mark.task
def task_write_text(): ...
"""
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = subprocess.run(
("pytest", tmp_path.joinpath("task_module.py").as_posix()),
capture_output=True,
check=False,
)
assert b"DeprecationWarning: '@pytask.mark.task'" in result.stdout