py2dag 0.2.1__tar.gz → 0.2.2__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.
- {py2dag-0.2.1 → py2dag-0.2.2}/PKG-INFO +1 -1
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/export_dagre.py +13 -2
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/export_svg.py +19 -2
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/parser.py +18 -3
- {py2dag-0.2.1 → py2dag-0.2.2}/pyproject.toml +1 -1
- {py2dag-0.2.1 → py2dag-0.2.2}/LICENSE +0 -0
- {py2dag-0.2.1 → py2dag-0.2.2}/README.md +0 -0
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/__init__.py +0 -0
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/cli.py +0 -0
- {py2dag-0.2.1 → py2dag-0.2.2}/py2dag/pseudo.py +0 -0
@@ -73,10 +73,21 @@ HTML_TEMPLATE = """<!doctype html>
|
|
73
73
|
g.setEdge(out.from, outId);
|
74
74
|
});
|
75
75
|
|
76
|
-
//
|
76
|
+
// Build index for source op lookup
|
77
|
+
const opById = {};
|
78
|
+
(plan.ops || []).forEach(op => { opById[op.id] = op; });
|
79
|
+
|
80
|
+
// Add dependency edges between ops with labels
|
77
81
|
(plan.ops || []).forEach(op => {
|
78
82
|
(op.deps || []).forEach(dep => {
|
79
|
-
|
83
|
+
const src = opById[dep];
|
84
|
+
let edgeLabel = dep; // default to SSA id
|
85
|
+
if (src && src.op === 'COND.eval') {
|
86
|
+
edgeLabel = 'cond';
|
87
|
+
} else if (src && src.op === 'ITER.eval') {
|
88
|
+
edgeLabel = (src.args && src.args.target) ? src.args.target : 'iter';
|
89
|
+
}
|
90
|
+
g.setEdge(dep, op.id, { label: edgeLabel });
|
80
91
|
});
|
81
92
|
});
|
82
93
|
|
@@ -22,10 +22,27 @@ def export(plan: Dict[str, Any], filename: str = "plan.svg") -> str:
|
|
22
22
|
raise RuntimeError("Python package 'graphviz' is required for SVG export")
|
23
23
|
|
24
24
|
graph = Digraph(format="svg")
|
25
|
-
|
25
|
+
|
26
|
+
# Index ops for edge label decisions
|
27
|
+
ops = list(plan.get("ops", []))
|
28
|
+
op_by_id = {op["id"]: op for op in ops}
|
29
|
+
|
30
|
+
# Nodes
|
31
|
+
for op in ops:
|
26
32
|
graph.node(op["id"], label=op["op"])
|
33
|
+
|
34
|
+
# Dependency edges with labels showing data/control
|
35
|
+
for op in ops:
|
27
36
|
for dep in op.get("deps", []):
|
28
|
-
|
37
|
+
src = op_by_id.get(dep)
|
38
|
+
label = dep # default to SSA id
|
39
|
+
if src is not None:
|
40
|
+
if src.get("op") == "COND.eval":
|
41
|
+
label = "cond"
|
42
|
+
elif src.get("op") == "ITER.eval":
|
43
|
+
args = src.get("args", {}) or {}
|
44
|
+
label = str(args.get("target") or "iter")
|
45
|
+
graph.edge(dep, op["id"], label=label)
|
29
46
|
for out in plan.get("outputs", []):
|
30
47
|
out_id = f"out:{out['as']}"
|
31
48
|
graph.node(out_id, label=out['as'], shape="note")
|
@@ -252,11 +252,14 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
252
252
|
ops.append({"id": ssa, "op": "COND.eval", "deps": deps, "args": {"expr": expr, "kind": kind}})
|
253
253
|
return ssa
|
254
254
|
|
255
|
-
def _emit_iter(node: ast.AST) -> str:
|
255
|
+
def _emit_iter(node: ast.AST, target_label: Optional[str] = None) -> str:
|
256
256
|
expr = _stringify(node)
|
257
257
|
deps = [_ssa_get(n) for n in _collect_value_deps(node)]
|
258
258
|
ssa = _ssa_new("iter")
|
259
|
-
|
259
|
+
args = {"expr": expr, "kind": "for"}
|
260
|
+
if target_label:
|
261
|
+
args["target"] = target_label
|
262
|
+
ops.append({"id": ssa, "op": "ITER.eval", "deps": deps, "args": args})
|
260
263
|
return ssa
|
261
264
|
|
262
265
|
def _parse_stmt(stmt: ast.stmt) -> Optional[str]:
|
@@ -383,7 +386,19 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
383
386
|
return None
|
384
387
|
elif isinstance(stmt, (ast.For, ast.AsyncFor)):
|
385
388
|
# ITER over iterable
|
386
|
-
|
389
|
+
# Determine loop target label if simple
|
390
|
+
t = stmt.target
|
391
|
+
t_label: Optional[str] = None
|
392
|
+
if isinstance(t, ast.Name):
|
393
|
+
t_label = t.id
|
394
|
+
elif isinstance(t, ast.Tuple) and all(isinstance(e, ast.Name) for e in t.elts):
|
395
|
+
t_label = ",".join(e.id for e in t.elts) # type: ignore[attr-defined]
|
396
|
+
else:
|
397
|
+
try:
|
398
|
+
t_label = ast.unparse(t) # type: ignore[attr-defined]
|
399
|
+
except Exception:
|
400
|
+
t_label = None
|
401
|
+
iter_id = _emit_iter(stmt.iter, target_label=t_label)
|
387
402
|
# Save pre-loop state
|
388
403
|
pre_versions = dict(versions)
|
389
404
|
pre_latest = dict(latest)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|