Skip to content

Remove unnecessary code from the collection of tasks. #497

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
Nov 16, 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 @@ -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

Expand Down
13 changes: 2 additions & 11 deletions src/_pytask/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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()