astrum 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.
astrum/__init__.py ADDED
@@ -0,0 +1,73 @@
1
+ from .config import AstrumConfig
2
+ from .decorators import (
3
+ DEFAULT_NAMESPACE,
4
+ RegisteredTask,
5
+ SchedulerRegistry,
6
+ active_namespace,
7
+ build_scheduler,
8
+ build_task_orders,
9
+ clear_registry,
10
+ get_registry,
11
+ run,
12
+ task,
13
+ use_namespace,
14
+ )
15
+ from .data_transport import F, T, From, Ref, To
16
+ from .models import (
17
+ ExecutionPlan,
18
+ ExecutionReport,
19
+ ExecutionStage,
20
+ ExecutionState,
21
+ SchedulerError,
22
+ StageStatus,
23
+ TaskAttemptStatistics,
24
+ TaskDependencyError,
25
+ TaskDuplicateExecutionError,
26
+ TaskExecutionStatistics,
27
+ TaskNotFoundError,
28
+ TaskOrder,
29
+ TaskOrderLoopError,
30
+ TaskOrderNoExitError,
31
+ TaskRegistrationError,
32
+ TaskStageStatistics,
33
+ )
34
+ from .planner import ExecutionPlanner
35
+ from .scheduler import DynamicScheduler
36
+
37
+ __all__ = [
38
+ "AstrumConfig",
39
+ "DynamicScheduler",
40
+ "ExecutionPlanner",
41
+ "SchedulerRegistry",
42
+ "RegisteredTask",
43
+ "DEFAULT_NAMESPACE",
44
+ "task",
45
+ "use_namespace",
46
+ "get_registry",
47
+ "clear_registry",
48
+ "active_namespace",
49
+ "build_task_orders",
50
+ "build_scheduler",
51
+ "run",
52
+ "Ref",
53
+ "From",
54
+ "To",
55
+ "F",
56
+ "T",
57
+ "ExecutionState",
58
+ "StageStatus",
59
+ "TaskOrder",
60
+ "ExecutionPlan",
61
+ "ExecutionStage",
62
+ "ExecutionReport",
63
+ "TaskStageStatistics",
64
+ "TaskAttemptStatistics",
65
+ "TaskExecutionStatistics",
66
+ "SchedulerError",
67
+ "TaskOrderLoopError",
68
+ "TaskOrderNoExitError",
69
+ "TaskDependencyError",
70
+ "TaskNotFoundError",
71
+ "TaskDuplicateExecutionError",
72
+ "TaskRegistrationError",
73
+ ]
astrum/config.py ADDED
@@ -0,0 +1,124 @@
1
+ """Astrum 全局调度引擎配置。
2
+
3
+ 通过一个不可变的 :class:`AstrumConfig` 数据类来集中管理调度器生命周期中
4
+ 所有可调节的行为参数。用户只需在 ``build_scheduler()`` / ``run()`` 时传入一个
5
+ config 实例即可一次性控制全部内部开关。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+ from dataclasses import dataclass, field
12
+ from typing import Any
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class AstrumConfig:
17
+ """Astrum 调度引擎一站式配置对象。
18
+
19
+ 所有参数均有安全的默认值,用户可按需覆盖。
20
+
21
+ **类型检查 / AST 推断**
22
+
23
+ - ``skip_type_check`` – 跳过 ``allow_data_model`` 的类型匹配校验。
24
+ 开启后 DataItem 上的类型约束将不会生效。默认 ``False``。
25
+ - ``infer_via_ast`` – 在函数缺少返回值注解 (``-> type``) 时,自动使用
26
+ AST 静态分析来推断返回类型。默认 ``False``。
27
+ - ``strict_topology`` – 严格拓扑校验模式。当 ``True`` 时,如果
28
+ data transport 推导出的 from/to 关系没有在 ``TaskData.from_tasks``
29
+ / ``to_tasks`` 中显式声明就会报错。默认 ``False``。
30
+
31
+ **数据传输**
32
+
33
+ - ``allow_no_dir_definition`` – 允许 DataItem 缺少来源或去向定义。
34
+ 在使用装饰器模式时通常设为 ``True``,因为框架会自动补全;手动模式下
35
+ 设为 ``False`` 可以捕捉用户遗漏。默认 ``True``。
36
+ - ``auto_sync_dependencies`` – 自动将 data transport 推导出来的
37
+ ``from_tasks`` 关系同步回任务图的 ``dependencies``。关闭后需用户
38
+ 手动声明 ``depends_on``。默认 ``True``。
39
+
40
+ **可视化**
41
+
42
+ - ``visualize`` – 在 DAG 构建完成后是否使用 Rich 在终端打印 DAG 树和
43
+ Data Transport Matrix。默认 ``False``。
44
+ - ``silence_warnings`` – 静默自动补全过程中的 DEBUG/WARNING 日志输出
45
+ (如 "undeclared relation has been automatically declared")。默认 ``False``。
46
+
47
+ **执行引擎**
48
+
49
+ - ``silence`` – 静默模式。当为 ``True`` 时调度器不输出执行期日志。
50
+ 默认 ``True``。
51
+ - ``concurrency_limit`` – 全局并发限制。设为 ``None`` 表示不限制;
52
+ 设为正整数 N 时,内部自动创建 ``asyncio.Semaphore(N)``。默认 ``None``。
53
+ - ``ignore_tail_task`` – 执行完成后不等待的末端任务列表。默认空列表。
54
+
55
+ Astrum's one-stop configuration object for the scheduling engine.
56
+
57
+ All parameters have safe defaults and can be overridden as needed.
58
+
59
+ **Type checking / AST inference**
60
+
61
+ - ``skip_type_check`` – Skip type matching validation for ``allow_data_model``.
62
+ When enabled, type constraints on DataItem will not take effect. Defaults to ``False``.
63
+ - ``infer_via_ast`` – When a function lacks a return value annotation
64
+ (``-> type``), automatically use AST static analysis to infer the return type.
65
+ Defaults to ``False``.
66
+ - ``strict_topology`` – Strict topology validation mode. When ``True``, an error
67
+ is raised if from/to relations inferred by data transport are not explicitly
68
+ declared in ``TaskData.from_tasks`` / ``to_tasks``. Defaults to ``False``.
69
+
70
+ **Data transport**
71
+
72
+ - ``allow_no_dir_definition`` – Allow DataItem to lack source or destination
73
+ definitions. This is usually set to ``True`` in decorator mode because the
74
+ framework completes them automatically; in manual mode, setting it to ``False``
75
+ can catch omissions. Defaults to ``True``.
76
+ - ``auto_sync_dependencies`` – Automatically sync ``from_tasks`` relations inferred
77
+ by data transport back to the task graph's ``dependencies``. When disabled,
78
+ users must manually declare ``depends_on``. Defaults to ``True``.
79
+
80
+ **Visualization**
81
+
82
+ - ``visualize`` – Whether to use Rich to print the DAG tree and Data Transport
83
+ Matrix in the terminal after DAG construction completes. Defaults to ``False``.
84
+ - ``silence_warnings`` – Silence DEBUG/WARNING log output during automatic
85
+ completion, such as "undeclared relation has been automatically declared".
86
+ Defaults to ``False``.
87
+
88
+ **Execution engine**
89
+
90
+ - ``silence`` – Silence mode. When ``True``, the scheduler does not output
91
+ execution-time logs. Defaults to ``True``.
92
+ - ``concurrency_limit`` – Global concurrency limit. Set to ``None`` for no limit;
93
+ set to a positive integer N to automatically create ``asyncio.Semaphore(N)``
94
+ internally. Defaults to ``None``.
95
+ - ``ignore_tail_task`` – List of tail tasks not to wait for after execution
96
+ completes. Defaults to an empty list.
97
+ """
98
+
99
+ # ── 类型检查 ──
100
+ skip_type_check: bool = False
101
+ infer_via_ast: bool = False
102
+ strict_topology: bool = False
103
+
104
+ # ── 数据传输 ──
105
+ allow_no_dir_definition: bool = True
106
+ auto_sync_dependencies: bool = True
107
+
108
+ # ── 可视化 ──
109
+ visualize: bool = False
110
+ silence_warnings: bool = False
111
+
112
+ # ── 执行引擎 ──
113
+ silence: bool = True
114
+ concurrency_limit: int | None = None
115
+ ignore_tail_task: list[str] = field(default_factory=list)
116
+
117
+ def build_semaphore(self) -> asyncio.Semaphore | None:
118
+ """根据 ``concurrency_limit`` 创建信号量对象。
119
+
120
+ Create a semaphore object according to ``concurrency_limit``.
121
+ """
122
+ if self.concurrency_limit is not None and self.concurrency_limit > 0:
123
+ return asyncio.Semaphore(self.concurrency_limit)
124
+ return None