Skip to content

Change CLI entrypoint and allow passing task function to pytask.build. #540

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
Dec 22, 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
2 changes: 2 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/_pytask/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/_pytask/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down