diff --git a/.github/workflows/python-test-ci.yml b/.github/workflows/python-test-ci.yml index 001101f3..c19c07a9 100644 --- a/.github/workflows/python-test-ci.yml +++ b/.github/workflows/python-test-ci.yml @@ -18,3 +18,4 @@ jobs: pip install pytest pytest-cov pip install --no-build-isolation --no-deps --disable-pip-version-check -e . python -m pytest --doctest-modules + python -m doctest -v docs/**/*.md diff --git a/docs/quickstart.md b/docs/quickstart.md index 27778e10..9ad06611 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -34,3 +34,34 @@ steps: default: 3 run: increment ``` + +### Programmatic Usage + +Building and rendering may be done programmatically, +which provides the opportunity to use custom renderers +and backends, as well as bespoke serialization or formatting. + +```python +>>> import sys +>>> import yaml +>>> from dewret.tasks import task, run +>>> from dewret.renderers.cwl import render +>>> +>>> @task() +... def increment(num: int): +... return num + 1 +>>> +>>> result = increment(num=3) +>>> workflow = run(result) +>>> cwl = render(workflow) +>>> yaml.dump(cwl, sys.stdout, indent=2) +class: Workflow +cwlVersion: 1.2 +steps: + increment-012ef3b3ffb9d15c3f2837aa4bb20a8d: + in: + num: + default: 3 + run: increment + +``` diff --git a/src/dewret/tasks.py b/src/dewret/tasks.py index 01de43e4..cc807a2f 100644 --- a/src/dewret/tasks.py +++ b/src/dewret/tasks.py @@ -21,9 +21,9 @@ Typical usage example: - @task() - def increment(num: int) -> int: - return num + 1 + >>> @task() + ... def increment(num: int) -> int: + ... return num + 1 """ import importlib @@ -41,11 +41,6 @@ class Backend(Enum): DEFAULT_BACKEND = Backend.DASK -def get_dask_backend() -> BackendModule: - """Initialize the dask backend.""" - from .backends import dask - return dask - class TaskManager: """Overarching backend-agnostic task manager. @@ -92,7 +87,7 @@ def backend(self) -> BackendModule: if backend is None: backend = self.set_backend(DEFAULT_BACKEND) - backend_mod = importlib.import_module(f".backends.{backend.value}", "dewret") + backend_mod = importlib.import_module(f".backends.backend_{backend.value}", "dewret") return backend_mod def make_lazy(self) -> LazyFactory: @@ -128,9 +123,9 @@ def task() -> Callable[[Target], StepExecution]: Decorator for the current backend to mark lazy-executable tasks. For example: - @task() - def increment(num: int) -> int: - return num + 1 + >>> @task() + ... def increment(num: int) -> int: + ... return num + 1 If the backend is `dask` (the default), it is will evaluate this as a `dask.delayed`. Note that, with any backend, dewret will diff --git a/tests/test_dask.py b/tests/test_dask.py index e90e0004..8d36912d 100644 --- a/tests/test_dask.py +++ b/tests/test_dask.py @@ -2,7 +2,7 @@ from typing import cast from dewret.workflow import Lazy -from dewret.backends.dask import lazy, run +from dewret.backends.backend_dask import lazy, run def inc_task(base: int) -> int: """Increments a value by one and returns it."""