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.

Parameters:

Name Type Description Default
*args Callable[..., Any] | Task

...

()
**kwargs Callable[..., Any]

...

{}

Raises:

Type 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.

Parameters:

Name Type Description Default
name str

name of the module.

required

Raises:

Type Description
NoTasksFoundError

Examples:

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

import_mykefile

import_mykefile(path: str) -> None

Import tasks from another Mykefile.

Parameters:

Name Type Description Default
path str

path to the Mykefile

required

Raises:

Type 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,
    root: bool | None = False,
    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).

Parameters:

Name Type Description Default
func Callable[..., str | Sequence[str]] | None

...

None
name str | None

name of the command.

None
parents str | tuple[str] | None

optional parents for the command.

None
root bool | None

if True, import this as the root command.

False
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

Returns:

Type 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,
    root: bool = False
) -> Callable[..., Any] | Callable[..., Callable[..., Any]]

Function decorator to register functions with myke.

Parameters:

Name Type Description Default
func Callable[..., Any] | None

...

None
name str | None

name of the command.

None
parents str | tuple[str | Command, ...] | None

optional parent(s) for the command.

None
root bool

if True, import this as the root command.

False

Returns:

Type 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}.')
...