pystepkit 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.
pystepkit/__init__.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""pystepkit:流程标记。只给对象挂属性并原样返回,不做任何包装,运行时零开销。"""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
__all__ = ["condition", "node", "outcome", "step", "workflow"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _mark(obj, kind: str, meta: dict):
|
|
9
|
+
obj.__flow_kind__ = kind
|
|
10
|
+
obj.__flow_meta__ = {k: v for k, v in meta.items() if v is not None}
|
|
11
|
+
return obj
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def workflow(
|
|
15
|
+
fn_or_cls=None,
|
|
16
|
+
*,
|
|
17
|
+
name: str | None = None,
|
|
18
|
+
title: str | None = None,
|
|
19
|
+
group: str | None = None,
|
|
20
|
+
version: str | None = None,
|
|
21
|
+
entry: str = "run",
|
|
22
|
+
):
|
|
23
|
+
"""标记一个工作流(函数或类)。`entry` 为类形式时的入口方法名。"""
|
|
24
|
+
meta = {"name": name, "title": title, "group": group, "version": version, "entry": entry}
|
|
25
|
+
|
|
26
|
+
def deco(obj):
|
|
27
|
+
return _mark(obj, "workflow", meta)
|
|
28
|
+
|
|
29
|
+
return deco if fn_or_cls is None else deco(fn_or_cls)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def step(fn=None, *, title: str | None = None):
|
|
33
|
+
"""标记一个步骤。"""
|
|
34
|
+
|
|
35
|
+
def deco(obj):
|
|
36
|
+
return _mark(obj, "step", {"title": title})
|
|
37
|
+
|
|
38
|
+
return deco if fn is None else deco(fn)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
node = step
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def condition(fn=None, *, title: str | None = None):
|
|
45
|
+
"""标记一个判断条件。"""
|
|
46
|
+
|
|
47
|
+
def deco(obj):
|
|
48
|
+
return _mark(obj, "condition", {"title": title})
|
|
49
|
+
|
|
50
|
+
return deco if fn is None else deco(fn)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def outcome(
|
|
54
|
+
kind: Literal["ok", "skipped", "failed"] = "ok", title: str | None = None, **fields
|
|
55
|
+
) -> dict:
|
|
56
|
+
"""构造步骤结果:普通字典。"""
|
|
57
|
+
result: dict = {"kind": kind}
|
|
58
|
+
if title is not None:
|
|
59
|
+
result["title"] = title
|
|
60
|
+
result.update(fields)
|
|
61
|
+
return result
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pystepkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pystepmap 的流程标记包:@workflow、@step、@condition、outcome,纯标记,零依赖
|
|
5
|
+
Project-URL: Homepage, https://github.com/xiaoyin1993/pystepmap
|
|
6
|
+
Project-URL: Repository, https://github.com/xiaoyin1993/pystepmap
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: decorators,flowchart,workflow
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# pystepkit
|
|
18
|
+
|
|
19
|
+
[pystepmap](https://github.com/xiaoyin1993/pystepmap) 的流程标记:`@workflow`、`@step` / `@node`、`@condition`、
|
|
20
|
+
`outcome(...)`。只给函数挂属性并原样返回,零依赖、运行时零开销。
|
|
21
|
+
|
|
22
|
+
pystepmap 不打标记也能分析代码;标记只用来给流程图起全中文的标题、分组,以及让 `pystepmap check` 检查编排约束。
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uv add pystepkit # 或者:pip install pystepkit
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from pystepkit import condition, outcome, step, workflow
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@step(title="扣减余额")
|
|
33
|
+
def debit(account, amount): ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@condition(title="余额够吗?")
|
|
37
|
+
def enough(account, amount) -> bool: ...
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@workflow(title="账户转账")
|
|
41
|
+
def transfer(account, amount):
|
|
42
|
+
if not enough(account, amount):
|
|
43
|
+
return outcome("failed", title="余额不足")
|
|
44
|
+
debit(account, amount)
|
|
45
|
+
return outcome("ok", title="转账成功")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
标记怎么写、四条约束各自禁止什么,见
|
|
49
|
+
[SKILL.md](https://github.com/xiaoyin1993/pystepmap/blob/main/.claude/skills/flow-style/SKILL.md)。
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
pystepkit/__init__.py,sha256=NscR5t1kxkmWWMsoAXC5MgTlNCkYkVTI-m9vyOk0CTI,1595
|
|
2
|
+
pystepkit-0.1.0.dist-info/METADATA,sha256=L6NZWeOAF0DvBr46kxZnQYQQd6ocWvhdWCXrS0FsI9k,1680
|
|
3
|
+
pystepkit-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
4
|
+
pystepkit-0.1.0.dist-info/licenses/LICENSE,sha256=HICk8hsyY79wgMfwv_NrePrNabVu1DyCrqQWyYt7Q4s,1072
|
|
5
|
+
pystepkit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 有礼貌的狼
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|