diff --git a/docs/source/changes.md b/docs/source/changes.md index 40cd0251..e3b5a07e 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -21,6 +21,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`496` makes pytask even lazier. Now, when a task produces a node whose hash remains the same, the consecutive tasks are not executed. It remained from when pytask relied on timestamps. +- {pull}`497` removes unnecessary code in the collection of tasks. ## 0.4.2 - 2023-11-08 diff --git a/src/_pytask/collect.py b/src/_pytask/collect.py index 6fcb1206..68170283 100644 --- a/src/_pytask/collect.py +++ b/src/_pytask/collect.py @@ -95,15 +95,6 @@ def _collect_from_paths(session: Session) -> None: def _collect_from_tasks(session: Session) -> None: """Collect tasks from user provided tasks via the functional interface.""" for raw_task in session.config.get("tasks", ()): - if isinstance(raw_task, PTask): - report = session.hook.pytask_collect_task_protocol( - session=session, - reports=session.collection_reports, - path=None, - name=None, - obj=raw_task, - ) - if is_task_function(raw_task): if not hasattr(raw_task, "pytask_meta"): raw_task = task_decorator()(raw_task) # noqa: PLW2901 @@ -127,8 +118,8 @@ def _collect_from_tasks(session: Session) -> None: name = raw_task.pytask_meta.name - # When a task is not a PTask and a callable, set arbitrary values and it will - # pass without errors and not collected. + # When a task is not a callable, it can be anything or a PTask. Set arbitrary + # values and it will pass without errors and not collected. else: name = "" path = None diff --git a/tests/test_execute.py b/tests/test_execute.py index e3b4bdac..c1107981 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -16,7 +16,9 @@ from pytask import build from pytask import cli from pytask import ExitCode +from pytask import PathNode from pytask import TaskOutcome +from pytask import TaskWithoutPath @pytest.mark.xfail(sys.platform == "win32", reason="See #293.") @@ -991,3 +993,18 @@ def task_second(path = Path("out.txt")) -> Annotated[str, Path("copy.txt")]: assert result.exit_code == ExitCode.OK assert "1 Succeeded" in result.output assert "1 Skipped because unchanged" in result.output + + +def test_use_functional_interface_with_task(tmp_path): + def func(path): + path.touch() + + task = TaskWithoutPath( + name="task", + function=func, + produces={"path": PathNode(path=tmp_path / "out.txt")}, + ) + + session = build(tasks=[task]) + assert session.exit_code == ExitCode.OK + assert tmp_path.joinpath("out.txt").exists()