Skip to content

Commit 651d402

Browse files
authored
Remove unnecessary code from the collection of tasks. (#497)
1 parent 3ad00a7 commit 651d402

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2121
- {pull}`496` makes pytask even lazier. Now, when a task produces a node whose hash
2222
remains the same, the consecutive tasks are not executed. It remained from when pytask
2323
relied on timestamps.
24+
- {pull}`497` removes unnecessary code in the collection of tasks.
2425

2526
## 0.4.2 - 2023-11-08
2627

src/_pytask/collect.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@ def _collect_from_paths(session: Session) -> None:
9595
def _collect_from_tasks(session: Session) -> None:
9696
"""Collect tasks from user provided tasks via the functional interface."""
9797
for raw_task in session.config.get("tasks", ()):
98-
if isinstance(raw_task, PTask):
99-
report = session.hook.pytask_collect_task_protocol(
100-
session=session,
101-
reports=session.collection_reports,
102-
path=None,
103-
name=None,
104-
obj=raw_task,
105-
)
106-
10798
if is_task_function(raw_task):
10899
if not hasattr(raw_task, "pytask_meta"):
109100
raw_task = task_decorator()(raw_task) # noqa: PLW2901
@@ -127,8 +118,8 @@ def _collect_from_tasks(session: Session) -> None:
127118

128119
name = raw_task.pytask_meta.name
129120

130-
# When a task is not a PTask and a callable, set arbitrary values and it will
131-
# pass without errors and not collected.
121+
# When a task is not a callable, it can be anything or a PTask. Set arbitrary
122+
# values and it will pass without errors and not collected.
132123
else:
133124
name = ""
134125
path = None

tests/test_execute.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from pytask import build
1717
from pytask import cli
1818
from pytask import ExitCode
19+
from pytask import PathNode
1920
from pytask import TaskOutcome
21+
from pytask import TaskWithoutPath
2022

2123

2224
@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")]:
991993
assert result.exit_code == ExitCode.OK
992994
assert "1 Succeeded" in result.output
993995
assert "1 Skipped because unchanged" in result.output
996+
997+
998+
def test_use_functional_interface_with_task(tmp_path):
999+
def func(path):
1000+
path.touch()
1001+
1002+
task = TaskWithoutPath(
1003+
name="task",
1004+
function=func,
1005+
produces={"path": PathNode(path=tmp_path / "out.txt")},
1006+
)
1007+
1008+
session = build(tasks=[task])
1009+
assert session.exit_code == ExitCode.OK
1010+
assert tmp_path.joinpath("out.txt").exists()

0 commit comments

Comments
 (0)