daguflow 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
daguflow/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ """daguflow: author dagu workflows in Python, Airflow-style.
2
+
3
+ from daguflow import dag, task, SubDAG, ForEach, Cron, env
4
+
5
+ @dag(schedule=Cron("0 9 * * *", tz="America/Los_Angeles"), labels=["reports"])
6
+ def morning_report(day: str = "today"):
7
+ '''Build and send the morning report.'''
8
+ data = fetch(day)
9
+ send(data)
10
+
11
+ `daguflow build <module> -o dags/` writes one YAML file per DAG.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from . import actions
17
+ from .dag import DAG, dag, on_abort, on_exit, on_failure, on_init, on_success, on_wait
18
+ from .groups import ExternalDAG, ForEach, SubDAG, call_dag
19
+ from .params import Doc, Length, Param, Pattern, Range
20
+ from .refs import ITEM, ParamRef, Ref, consts, ctx, env, raw, var
21
+ from .schedule import At, Cron, StartStop
22
+ from .schema import DAGU_VERSION
23
+ from .step import Action, Step, chain, shell, step
24
+ from .targets import ContainerTarget, SSHTarget, container
25
+ from .task import task
26
+
27
+ __version__ = "0.1.0"
28
+
29
+ __all__ = [
30
+ "DAG", "DAGU_VERSION", "ITEM", "Action", "At", "ContainerTarget", "Cron", "Doc", "ExternalDAG",
31
+ "ForEach", "Length", "Param", "ParamRef", "Pattern", "Range", "Ref", "SSHTarget", "StartStop",
32
+ "Step", "SubDAG", "actions", "call_dag", "chain", "consts", "container", "ctx", "dag", "env",
33
+ "on_abort", "on_exit", "on_failure", "on_init", "on_success", "on_wait", "raw", "shell", "step",
34
+ "task", "var",
35
+ ]
daguflow/_context.py ADDED
@@ -0,0 +1,46 @@
1
+ """The stack of open DAG / sub-DAG / foreach / handler blocks.
2
+
3
+ A Step created while a block is open joins the innermost one, the way an
4
+ Airflow operator joins the `with DAG(...)` it is created in.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import threading
10
+ from typing import TYPE_CHECKING
11
+
12
+ if TYPE_CHECKING:
13
+ from .step import Container
14
+
15
+ _local = threading.local()
16
+
17
+
18
+ def _stack() -> list[Container]:
19
+ if not hasattr(_local, "stack"):
20
+ _local.stack = []
21
+ return _local.stack
22
+
23
+
24
+ def push(container: Container) -> None:
25
+ _stack().append(container)
26
+
27
+
28
+ def pop(container: Container) -> None:
29
+ stack = _stack()
30
+ if not stack or stack[-1] is not container:
31
+ raise RuntimeError("daguflow blocks closed out of order")
32
+ stack.pop()
33
+
34
+
35
+ def current() -> Container | None:
36
+ stack = _stack()
37
+ return stack[-1] if stack else None
38
+
39
+
40
+ def current_dag():
41
+ from .dag import DAG
42
+
43
+ for container in reversed(_stack()):
44
+ if isinstance(container, DAG):
45
+ return container
46
+ return None
daguflow/_types.py ADDED
@@ -0,0 +1,12 @@
1
+ """Typing helpers shared by the generated builders."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TypeVar, Union
6
+
7
+ from .refs import Ref
8
+
9
+ T = TypeVar("T")
10
+
11
+ # A value or a Ref that dagu fills in at run time.
12
+ Val = Union[T, Ref]
@@ -0,0 +1,37 @@
1
+ """Typed builders for dagu actions.
2
+
3
+ from daguflow import actions
4
+ actions.http.request(method="GET", url="https://example.com").step("fetch")
5
+
6
+ Every builtin action at the vendored dagu version has a builder (generated
7
+ from the schema; see tools/gen_actions.py). Each returns an Action, which
8
+ becomes a step through `.step(...)`, by being returned from a @task, or
9
+ through `Step(action=...)`. `custom()` covers custom actions declared in
10
+ `actions:` and remote ones (`owner/repo@v1`, `name@v1`, `source:...@v1`);
11
+ `redis()` covers the `redis.<op>` family.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from typing import Any
17
+
18
+ from ..step import Action
19
+ from ..targets import SSHTarget
20
+ from ._generated import * # noqa: F403
21
+ from ._generated import __all__ as _generated_all
22
+ from ._generated import ssh
23
+
24
+ ssh.Target = SSHTarget # type: ignore[attr-defined]
25
+
26
+
27
+ def custom(name: str, **with_: Any) -> Action:
28
+ """A custom or remote action: `custom("dagucloud/duckdb@v1", query=...)`."""
29
+ return Action(name, with_)
30
+
31
+
32
+ def redis(op: str, **with_: Any) -> Action:
33
+ """`redis.<op>`: `redis("get", key="k")`."""
34
+ return Action(f"redis.{op}", with_)
35
+
36
+
37
+ __all__ = [*_generated_all, "custom", "redis", "Action", "SSHTarget"]