From 14666036515db400aaf4110dccf82bf4ad763371 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Fri, 22 Dec 2023 16:46:58 +0100 Subject: [PATCH] Change CLI entrypoint and allow passing task function to pytask.build. --- docs/source/changes.md | 2 ++ pyproject.toml | 2 +- src/_pytask/build.py | 9 +++++---- src/_pytask/collect.py | 3 ++- tests/test_execute.py | 3 +++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index bb1c74e8..8e44dec1 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -23,6 +23,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`528` improves the codecov setup and coverage. - {pull}`535` reenables and fixes tests with Jupyter. - {pull}`536` allows partialed functions to be task functions. +- {pull}`540` changes the CLI entry-point and allow `pytask.build(tasks=task_func)` as + the signatures suggested. ## 0.4.4 - 2023-12-04 diff --git a/pyproject.toml b/pyproject.toml index f5942471..dce6e6ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,7 +87,7 @@ Homepage = "https://pytask-dev.readthedocs.io/en/stable" Tracker = "https://github.com/pytask-dev/pytask/issues" [project.scripts] -pytask = "_pytask.cli:cli" +pytask = "pytask:cli" [tool.setuptools] include-package-data = true diff --git a/src/_pytask/build.py b/src/_pytask/build.py index 754d343c..85e1c883 100644 --- a/src/_pytask/build.py +++ b/src/_pytask/build.py @@ -127,8 +127,8 @@ def build( # noqa: C901, PLR0912, PLR0913 force Run tasks even though they would be skipped since nothing has changed. ignore - A pattern to ignore files or directories. Refer to ``pathlib.Path.match`` - for more info. + A pattern to ignore files or directories. Refer to ``pathlib.Path.match`` for + more info. marker_expression Same as ``-m`` on the command line. Select tasks via marker expressions. max_failures @@ -145,7 +145,7 @@ def build( # noqa: C901, PLR0912, PLR0913 Start a custom debugger on errors. For example: ``--pdbcls=IPython.terminal.debugger:TerminalPdb`` s - Shortcut for ``pytask.build(capture"no")``. + Shortcut for ``capture="no"``. show_capture Choose which captured output should be shown for failed tasks. show_errors_immediately @@ -161,7 +161,8 @@ def build( # noqa: C901, PLR0912, PLR0913 strict_markers Raise errors for unknown markers. tasks - A task or a collection of tasks that is passed to ``pytask.build(tasks=...)``. + A task or a collection of tasks which can be callables or instances following + {class}`~pytask.PTask`. task_files A pattern to describe modules that contain tasks. trace diff --git a/src/_pytask/collect.py b/src/_pytask/collect.py index 04ac49c4..c04335c3 100644 --- a/src/_pytask/collect.py +++ b/src/_pytask/collect.py @@ -38,6 +38,7 @@ from _pytask.path import shorten_path from _pytask.reports import CollectionReport from _pytask.shared import find_duplicates +from _pytask.shared import to_list from _pytask.task_utils import COLLECTED_TASKS from _pytask.task_utils import task as task_decorator from _pytask.typing import is_task_function @@ -103,7 +104,7 @@ 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", ()): + for raw_task in to_list(session.config.get("tasks", ())): if is_task_function(raw_task): if not hasattr(raw_task, "pytask_meta"): raw_task = task_decorator()(raw_task) # noqa: PLW2901 diff --git a/tests/test_execute.py b/tests/test_execute.py index c1cc5da2..d9774dfb 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -988,6 +988,9 @@ def func(path): assert session.exit_code == ExitCode.OK assert tmp_path.joinpath("out.txt").exists() + session = build(tasks=task) + assert session.exit_code == ExitCode.OK + def test_collect_task(runner, tmp_path): source = """