pystepkit 0.1.0__tar.gz

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.
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .superpowers/
6
+ .ruff_cache/
7
+ .claude/settings.local.json
8
+ # 从 .mcp.json.example 复制出来的本机配置:不要提交(见 README「在 Claude Code 里使用」)
9
+ .mcp.json
10
+ # 只留在本机、不进 git 的东西(试验代码等)
11
+ local/
@@ -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.
@@ -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,33 @@
1
+ # pystepkit
2
+
3
+ [pystepmap](https://github.com/xiaoyin1993/pystepmap) 的流程标记:`@workflow`、`@step` / `@node`、`@condition`、
4
+ `outcome(...)`。只给函数挂属性并原样返回,零依赖、运行时零开销。
5
+
6
+ pystepmap 不打标记也能分析代码;标记只用来给流程图起全中文的标题、分组,以及让 `pystepmap check` 检查编排约束。
7
+
8
+ ```bash
9
+ uv add pystepkit # 或者:pip install pystepkit
10
+ ```
11
+
12
+ ```python
13
+ from pystepkit import condition, outcome, step, workflow
14
+
15
+
16
+ @step(title="扣减余额")
17
+ def debit(account, amount): ...
18
+
19
+
20
+ @condition(title="余额够吗?")
21
+ def enough(account, amount) -> bool: ...
22
+
23
+
24
+ @workflow(title="账户转账")
25
+ def transfer(account, amount):
26
+ if not enough(account, amount):
27
+ return outcome("failed", title="余额不足")
28
+ debit(account, amount)
29
+ return outcome("ok", title="转账成功")
30
+ ```
31
+
32
+ 标记怎么写、四条约束各自禁止什么,见
33
+ [SKILL.md](https://github.com/xiaoyin1993/pystepmap/blob/main/.claude/skills/flow-style/SKILL.md)。
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "pystepkit"
3
+ version = "0.1.0"
4
+ description = "pystepmap 的流程标记包:@workflow、@step、@condition、outcome,纯标记,零依赖"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = "MIT"
8
+ dependencies = []
9
+ keywords = ["flowchart", "workflow", "decorators"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ ]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/xiaoyin1993/pystepmap"
19
+ Repository = "https://github.com/xiaoyin1993/pystepmap"
20
+
21
+ [build-system]
22
+ requires = ["hatchling"]
23
+ build-backend = "hatchling.build"
24
+
25
+ [tool.hatch.build.targets.wheel]
26
+ packages = ["src/pystepkit"]
@@ -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,34 @@
1
+ from pystepkit import condition, node, outcome, step, workflow
2
+
3
+
4
+ def test_bare_and_called_forms_return_same_object():
5
+ async def a(): ...
6
+ def b(): ...
7
+ assert step(a) is a and a.__flow_kind__ == "step" and a.__flow_meta__ == {}
8
+ assert step(title="取回原文")(b) is b and b.__flow_meta__ == {"title": "取回原文"}
9
+
10
+ def test_node_is_step():
11
+ assert node is step
12
+
13
+ def test_condition_and_workflow_on_function():
14
+ @condition(title="余额充足?")
15
+ def has_balance(ctx): return True
16
+ @workflow(title="账户转账", group="转账")
17
+ async def transfer(ctx): ...
18
+ assert has_balance.__flow_kind__ == "condition"
19
+ assert transfer.__flow_kind__ == "workflow"
20
+ assert transfer.__flow_meta__ == {"title": "账户转账", "group": "转账", "entry": "run"}
21
+
22
+ def test_workflow_on_class():
23
+ @workflow(name="TransferWorkflow", title="账户转账", version="1.0")
24
+ class TransferWorkflow:
25
+ async def run(self, ctx): ...
26
+ @node(title="参数校验")
27
+ async def validate(self, ctx): ...
28
+ assert TransferWorkflow.__flow_kind__ == "workflow"
29
+ assert TransferWorkflow.__flow_meta__["version"] == "1.0"
30
+ assert TransferWorkflow.validate.__flow_meta__ == {"title": "参数校验"}
31
+
32
+ def test_outcome_is_plain_dict():
33
+ assert outcome("skipped", reason="whitelisted") == {"kind": "skipped", "reason": "whitelisted"}
34
+ assert outcome(title="完成") == {"kind": "ok", "title": "完成"}