Skip to content

myke.task

Functions for registering tasks with myke.

Functions

add_tasks

add_tasks(*args: Callable[..., Any] | Task, **kwargs: Callable[..., Any]) -> None

Register the given callable(s) with myke.

PARAMETER DESCRIPTION
*args

...

TYPE: Callable[..., Any] | Task DEFAULT: ()

**kwargs

...

TYPE: Callable[..., Any] DEFAULT: {}

RAISES DESCRIPTION
TaskAlreadyRegisteredError

...

Examples:

>>> import myke
...
>>> def say_hello(name):
...    print(f'Hello {name}.')
...
>>> def say_goodbye(name):
...    print(f'Goodbye {name}.')
...
>>> myke.add_tasks(say_hello, say_goodbye)

import_module

import_module(name: str) -> None

Import tasks from the given Python module.

PARAMETER DESCRIPTION
name

name of the module.

TYPE: str

RAISES DESCRIPTION
NoTasksFoundError

Examples:

>>> import myke
...
>>> myke.import_module('python_pkg.python_module')

import_mykefile

import_mykefile(path: str | Path) -> None

Import tasks from another Mykefile.

PARAMETER DESCRIPTION
path

path to the Mykefile

TYPE: str | Path

RAISES DESCRIPTION
NoTasksFoundError

Examples:

>>> import myke
...
>>> myke.import_mykefile('/path/to/tasks.py')

shell_task

shell_task(func: Callable[..., str | Sequence[str]] | None = None, *, name: str | None = None, parents: str | tuple[str] | None = None, capture_output: bool | None = False, echo: bool | None = True, check: bool | None = True, cwd: str | None = None, env: dict[str, str] | None = None, env_update: dict[str, str | None] | None = None, timeout: float | None = None, executable: str | None = None) -> Callable[..., CompletedProcess[bytes | str]] | Callable[..., Callable[..., CompletedProcess[bytes | str]]]

Function decorator to register shell commands with myke.

myke expects the function to return a string of one or more shell-commands, and will invoke the commands using myke.run(..., shell=True).

PARAMETER DESCRIPTION
func

...

TYPE: Callable[..., str | Sequence[str]] | None DEFAULT: None

name

name of the command.

TYPE: str | None DEFAULT: None

parents

optional parents for the command.

TYPE: str | tuple[str] | None DEFAULT: None

capture_output

...

TYPE: bool | None DEFAULT: False

echo

...

TYPE: bool | None DEFAULT: True

check

...

TYPE: bool | None DEFAULT: True

cwd

...

TYPE: str | None DEFAULT: None

env

...

TYPE: dict[str, str] | None DEFAULT: None

env_update

...

TYPE: dict[str, str | None] | None DEFAULT: None

timeout

...

TYPE: float | None DEFAULT: None

executable

...

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
Callable[..., CompletedProcess[bytes | str]] | Callable[..., Callable[..., CompletedProcess[bytes | str]]]

...

Examples:

>>> from myke import shell_task
...
>>> @shell_task
... def say_hello(name):
...    return f"echo 'Hello {name}.'"
...
>>> @shell_task
... def say_goodbye(name):
...    return f"echo 'Goodbye {name}.'"
...

task

task(func: Callable[..., Any] | None = None, *, name: str | None = None, parents: str | tuple[str | yapx.Command, ...] | None = None, shell: bool = False) -> Callable[..., Any] | Callable[..., Callable[..., Any]]

Function decorator to register functions with myke.

PARAMETER DESCRIPTION
func

...

TYPE: Callable[..., Any] | None DEFAULT: None

name

name of the command.

TYPE: str | None DEFAULT: None

parents

optional parent(s) for the command.

TYPE: str | tuple[str | Command, ...] | None DEFAULT: None

shell

if True, act as @shell_task.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Callable[..., Any] | Callable[..., Callable[..., Any]]

...

Examples:

>>> from myke import task
...
>>> @task
... def say_hello(name):
...    print(f'Hello {name}.')
...
>>> @task
... def say_goodbye(name):
...    print(f'Goodbye {name}.')
...