Skip to content

Invoke tasklib

invoke_tasklib

Reusable Invoke tasks shared across Python projects.

Typical usage in a consuming project's tasks.py::

from invoke_tasklib import make_ns

ns = make_ns()

and an invoke.yaml at the project root::

tasklib:
  package:
    name: my_package

To compose a custom subset of tasks, use the exclude and include options of make_ns, or import individual task modules (the module of the test tasks is testing, so its collection needs the name test to keep the task names: each task module has it in its NAMESPACE constant):

>>> from invoke.collection import Collection
>>> from invoke_tasklib import lint, testing
>>> test = Collection.from_module(testing, name=testing.NAMESPACE)
>>> ns = Collection(lint, test)
>>> sorted(ns.task_names)
['lint.check-python', 'lint.check-spelling', 'lint.fix-python',
 'lint.pre-commit', 'test.all', 'test.benchmark',
 'test.coverage-report', 'test.doctest', 'test.doctest-markdown',
 'test.doctest-src', 'test.functional', 'test.integration', 'test.unit']

invoke_tasklib.__version__ module-attribute

__version__ = _installed_version()

The version of the installed invoke-tasklib distribution.

invoke_tasklib.make_ns

make_ns(
    *,
    exclude: str | Iterable[str] = (),
    include: str | Iterable[str] | None = None,
) -> Collection

Build a new collection of the tasks, optionally restricted.

Each call returns a new collection, so a project can add its own tasks to it or remove some without any effect on other importers.

Parameters:

Name Type Description Default
exclude str | Iterable[str]

Names of the namespaces ("doc") or of the tasks ("release.publish") to leave out. A single string is one name.

()
include str | Iterable[str] | None

Names of the namespaces or of the tasks to keep. If None, all the tasks are kept. exclude is applied to what include keeps. A single string is one name.

None

Returns:

Type Description
Collection

A new collection. The defaults of the tasklib config are

Collection

registered on it, so that they can be overridden with the

Collection

INVOKE_TASKLIB_<SECTION>_<KEY> environment variables (for

Collection

example INVOKE_TASKLIB_PATHS_SRC).

Raises:

Type Description
ValueError

If a name of exclude or include is not a namespace or a task, which is usually a typo.

Warns:

Type Description
RuntimeWarning

On Windows, which is not supported (the tasks need a POSIX shell).

Example usage:

>>> from invoke_tasklib import make_ns
>>> ns = make_ns(include=["lint.check-python", "test.unit"])
>>> sorted(ns.task_names)
['lint.check-python', 'test.unit']

options: members: - make_ns - version