py2dag 0.3.9__py3-none-any.whl → 0.3.11__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.
py2dag/parser.py CHANGED
@@ -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
- lit_val = _literal(v_node)
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
- lit = _literal(stmt.value)
513
- const_id = _ssa_new("return_value")
514
- ops.append({
515
- "id": const_id,
516
- "op": "CONST.value",
517
- "deps": [],
518
- "args": {"value": lit},
519
- })
520
- returned_var = const_id
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: py2dag
3
- Version: 0.3.9
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
 
@@ -0,0 +1,12 @@
1
+ py2dag/__init__.py,sha256=i8VB44JCVcRJAcvnQtbH8YVRUz5j7dE355iRbikXPGQ,250
2
+ py2dag/cli.py,sha256=q8ocafpGtkrls1mx9QiFU1wL6KKeeJhT0Oklk6SwHB0,15151
3
+ py2dag/colors.py,sha256=kVMVWUKJY1uLQFQux5XKiEcofDFpNPQoAEzpMJWs2b0,604
4
+ py2dag/export_dagre.py,sha256=Og-oVjKzc7bRgeU7rgLHDjiY6wIcNyr2nIYlSAQzKoM,6041
5
+ py2dag/export_svg.py,sha256=3ZmZqxIUidSbuKIIh5kFqhfVnoqZ6PbEQpMih4AX9xo,3793
6
+ py2dag/parser.py,sha256=5I9bCHd0m1iPADyMuBu8yXxQ2tDOktyfFXre6bT2taw,37622
7
+ py2dag/pseudo.py,sha256=NJK61slyFLtSjhj8gJDJneUInEpBN57_41g8IfHNPWI,922
8
+ py2dag-0.3.11.dist-info/LICENSE,sha256=3Qee1EPwej_nusovTbyIQ8LvD2rXHdM0c6LNwk_D8Kc,1067
9
+ py2dag-0.3.11.dist-info/METADATA,sha256=NUFd7P9MzCKnTmIyox0e_G-GJZcbLtMuIluNisIFx_c,4024
10
+ py2dag-0.3.11.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ py2dag-0.3.11.dist-info/entry_points.txt,sha256=Q0SHexJJ0z1te4AYL1xTZogx5FrxCCE1ZJ5qntkFMZs,42
12
+ py2dag-0.3.11.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- py2dag/__init__.py,sha256=i8VB44JCVcRJAcvnQtbH8YVRUz5j7dE355iRbikXPGQ,250
2
- py2dag/cli.py,sha256=q8ocafpGtkrls1mx9QiFU1wL6KKeeJhT0Oklk6SwHB0,15151
3
- py2dag/colors.py,sha256=kVMVWUKJY1uLQFQux5XKiEcofDFpNPQoAEzpMJWs2b0,604
4
- py2dag/export_dagre.py,sha256=Og-oVjKzc7bRgeU7rgLHDjiY6wIcNyr2nIYlSAQzKoM,6041
5
- py2dag/export_svg.py,sha256=3ZmZqxIUidSbuKIIh5kFqhfVnoqZ6PbEQpMih4AX9xo,3793
6
- py2dag/parser.py,sha256=WKLT-2qYpcGvlwU9hQ7o9wIFIxU328mlp8ntaAai5KY,37026
7
- py2dag/pseudo.py,sha256=NJK61slyFLtSjhj8gJDJneUInEpBN57_41g8IfHNPWI,922
8
- py2dag-0.3.9.dist-info/LICENSE,sha256=3Qee1EPwej_nusovTbyIQ8LvD2rXHdM0c6LNwk_D8Kc,1067
9
- py2dag-0.3.9.dist-info/METADATA,sha256=hNWrZlCHmkhmXCpE95zLL7PIMMemkI92bJrhWRzbjTw,3549
10
- py2dag-0.3.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
- py2dag-0.3.9.dist-info/entry_points.txt,sha256=Q0SHexJJ0z1te4AYL1xTZogx5FrxCCE1ZJ5qntkFMZs,42
12
- py2dag-0.3.9.dist-info/RECORD,,