Task discovery#

How to discover tasks#

All ewoks tasks provided by one or more python modules can be discovered as follows

from ewokscore.task_discovery import discover_tasks_from_modules

tasks = discover_tasks_from_modules(
    "myproject.module1",
    "myproject.module2",
    task_type="class",
)

The task_type can have one of these values

  • “class” (default): the module defines an ewoks task class or imports other modules that define ewoks task classes

  • “method”: all public methods in the module are assumed to be ewoks tasks

  • “ppfmethod”: the “run” method in the module is assumed to be an ewoks task

To discover all tasks provided by all installed python packages

from ewokscore.task_discovery import discover_all_tasks

tasks = discover_all_tasks(task_type="class")

The task discovery mechanism searches for tasks inside python packages and modules.

For example

tasks = discover_tasks_from_modules(
    "myproject.tasks.*"
)

could discover task classes such as

myproject/tasks/demo.py      # MyDemoTask1, MyDemoTask2
myproject/tasks/example.py   # MyTask1, MyTask2

The wildcard “*” matches exactly one package or module name component.

How to declare tasks to be discovered#

For automatic discovery to work across installed packages, a package that provides ewoks tasks should declare its task modules via the entry point mechanism.

# pyproject.toml

[project.entry-points."ewoks.tasks.class"]
"myproject.module1.submoduleA" = "myproject1"
"myproject.*.tasks" = "myproject2"

[project.entry-points."ewoks.tasks.method"]
"myproject.module3.submodule" = "myproject3"

[project.entry-points."ewoks.tasks.ppfmethod"]
"myproject.actors.*" = "myproject4"

The group names can be

  • “ewoks.tasks.class”

  • “ewoks.tasks.method”

  • “ewoks.tasks.ppfmethod”

The keys are the module patterns in which to discover tasks.

The values are ignored but typically the project name is used so the entry point can be loaded like any python entry point even though it is not used this way.

For example, the entry point

[project.entry-points."ewoks.tasks.class"]
"myproject.tasks.*" = "myproject1"

can declare task classes such as

myproject/tasks/demo.py      # MyDemoTask1, MyDemoTask2
myproject/tasks/example.py   # MyTask1, MyTask2

A project that provides ewoks tasks can also add the “ewoks” keyword to be discoverable in a package repository like PyPI:

# pyproject.toml

[project]
name = "myproject"
keywords = ["ewoks"]