py2dag 0.3.9__tar.gz → 0.3.11__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.3.9 → py2dag-0.3.11}/PKG-INFO +14 -5
- {py2dag-0.3.9 → py2dag-0.3.11}/README.md +13 -4
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/parser.py +21 -11
- {py2dag-0.3.9 → py2dag-0.3.11}/pyproject.toml +1 -1
- {py2dag-0.3.9 → py2dag-0.3.11}/LICENSE +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/__init__.py +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/cli.py +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/colors.py +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/export_dagre.py +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/export_svg.py +0 -0
- {py2dag-0.3.9 → py2dag-0.3.11}/py2dag/pseudo.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: py2dag
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.11
|
4
4
|
Summary: Convert Python function plans to DAG (JSON, pseudo, optional SVG).
|
5
5
|
License: MIT
|
6
6
|
Author: rvergis
|
@@ -18,7 +18,16 @@ Requires-Dist: graphviz (>=0.20.3,<0.21.0) ; extra == "svg"
|
|
18
18
|
Description-Content-Type: text/markdown
|
19
19
|
|
20
20
|
# py2dag
|
21
|
-
Convert Python function plans to a DAG (JSON, pseudo, optional SVG).
|
21
|
+
Convert Python function plans to a DAG (JSON, pseudo, optional HTML/SVG).
|
22
|
+
|
23
|
+
## Features
|
24
|
+
|
25
|
+
- Writes `plan.json` with explicit `nodes` and `edges` for downstream tools.
|
26
|
+
- Generates human-readable pseudo code at `plan.pseudo`.
|
27
|
+
- Optional exports:
|
28
|
+
- `--html` for an interactive Dagre graph with color-coded nodes.
|
29
|
+
- `--svg` for a Graphviz-rendered SVG.
|
30
|
+
- Node colors are chosen deterministically so the same op type is colored consistently across runs.
|
22
31
|
|
23
32
|
## Install
|
24
33
|
|
@@ -64,17 +73,17 @@ make run FILE=path/to/your_file.py ARGS=--html
|
|
64
73
|
- Run the installed CLI (after `pip install py2dag`):
|
65
74
|
|
66
75
|
```
|
67
|
-
py2dag path/to/your_file.py --html
|
76
|
+
py2dag path/to/your_file.py --html # interactive HTML
|
77
|
+
py2dag path/to/your_file.py --svg # Graphviz SVG
|
68
78
|
```
|
69
79
|
|
70
|
-
|
71
80
|
- Or directly with Python (inside venv):
|
72
81
|
|
73
82
|
```
|
74
83
|
poetry run python cli.py path/to/your_file.py --html
|
75
84
|
```
|
76
85
|
|
77
|
-
This generates `plan.json`, `plan.pseudo`, and if `--html` is used, `plan.html`.
|
86
|
+
This generates `plan.json`, `plan.pseudo`, and if `--html`/`--svg` is used, `plan.html` or `plan.svg`.
|
78
87
|
|
79
88
|
- Function name: By default the tool auto-detects a suitable function in the file. To target a specific function, pass `--func NAME`.
|
80
89
|
|
@@ -1,5 +1,14 @@
|
|
1
1
|
# py2dag
|
2
|
-
Convert Python function plans to a DAG (JSON, pseudo, optional SVG).
|
2
|
+
Convert Python function plans to a DAG (JSON, pseudo, optional HTML/SVG).
|
3
|
+
|
4
|
+
## Features
|
5
|
+
|
6
|
+
- Writes `plan.json` with explicit `nodes` and `edges` for downstream tools.
|
7
|
+
- Generates human-readable pseudo code at `plan.pseudo`.
|
8
|
+
- Optional exports:
|
9
|
+
- `--html` for an interactive Dagre graph with color-coded nodes.
|
10
|
+
- `--svg` for a Graphviz-rendered SVG.
|
11
|
+
- Node colors are chosen deterministically so the same op type is colored consistently across runs.
|
3
12
|
|
4
13
|
## Install
|
5
14
|
|
@@ -45,17 +54,17 @@ make run FILE=path/to/your_file.py ARGS=--html
|
|
45
54
|
- Run the installed CLI (after `pip install py2dag`):
|
46
55
|
|
47
56
|
```
|
48
|
-
py2dag path/to/your_file.py --html
|
57
|
+
py2dag path/to/your_file.py --html # interactive HTML
|
58
|
+
py2dag path/to/your_file.py --svg # Graphviz SVG
|
49
59
|
```
|
50
60
|
|
51
|
-
|
52
61
|
- Or directly with Python (inside venv):
|
53
62
|
|
54
63
|
```
|
55
64
|
poetry run python cli.py path/to/your_file.py --html
|
56
65
|
```
|
57
66
|
|
58
|
-
This generates `plan.json`, `plan.pseudo`, and if `--html` is used, `plan.html`.
|
67
|
+
This generates `plan.json`, `plan.pseudo`, and if `--html`/`--svg` is used, `plan.html` or `plan.svg`.
|
59
68
|
|
60
69
|
- Function name: By default the tool auto-detects a suitable function in the file. To target a specific function, pass `--func NAME`.
|
61
70
|
|
@@ -298,8 +298,14 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
298
298
|
tmp_id = _emit_assign_from_call(f"{var_name}_field", v_node)
|
299
299
|
deps.append(tmp_id)
|
300
300
|
else:
|
301
|
-
# Synthesize const for literal value
|
302
|
-
|
301
|
+
# Synthesize const for literal or arbitrary expression value
|
302
|
+
try:
|
303
|
+
lit_val = _literal(v_node)
|
304
|
+
except DSLParseError:
|
305
|
+
try:
|
306
|
+
lit_val = ast.unparse(v_node) # type: ignore[attr-defined]
|
307
|
+
except Exception:
|
308
|
+
lit_val = v_node.__class__.__name__
|
303
309
|
tmp = _ssa_new(f"{var_name}_lit")
|
304
310
|
ops.append({
|
305
311
|
"id": tmp,
|
@@ -509,15 +515,19 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
509
515
|
})
|
510
516
|
returned_var = const_id
|
511
517
|
elif isinstance(stmt.value, (ast.Constant, ast.List, ast.Tuple, ast.Dict)):
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
"
|
516
|
-
|
517
|
-
"
|
518
|
-
|
519
|
-
|
520
|
-
|
518
|
+
try:
|
519
|
+
lit = _literal(stmt.value)
|
520
|
+
except DSLParseError:
|
521
|
+
returned_var = _emit_assign_from_literal_or_pack("return_value", stmt.value)
|
522
|
+
else:
|
523
|
+
const_id = _ssa_new("return_value")
|
524
|
+
ops.append({
|
525
|
+
"id": const_id,
|
526
|
+
"op": "CONST.value",
|
527
|
+
"deps": [],
|
528
|
+
"args": {"value": lit},
|
529
|
+
})
|
530
|
+
returned_var = const_id
|
521
531
|
else:
|
522
532
|
raise DSLParseError("return must return a variable name or literal")
|
523
533
|
return None
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|