py2wf: a compiler from plain Python scripts to operator DAG workflows (.py → .pyt → workflow) #6618
carloea2
started this conversation in
Show and tell
Replies: 1 comment
-
|
@carloea2 Can you include a screenshot of the generated workflow? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Original Program:
Manually Translated Workflow:

This tool result:

Summary
I have an MVP of
python_to_workflow(underpy2udf/src/main/python/python_to_workflow/): a compiler that takes an ordinary single-file Python script and turns it into a runnable operator DAG, using one simple, predictable rule:The output is a
.pytfile, still plain, executable Python, but structured so each operator is a function with explicit input/output ports, and from there a workflow JSON of stockPythonUDFV2operators that the engine accepts today.The 1-line-1-operator form
pipeline.compile(source)emits the finest-grained form, which we call P⊥:_main()orchestrator keeps control flow visible,for/while/ifstay as ordinary statements in_main._<var>_N(ctx, live_in) -> live_out, including loop predicates and iterables.ctx), registered by reference so operators can read them without threading.Example (input → P⊥ shape):
P⊥ is deliberately fine-grained.
The grouping heuristic: N contiguous lines = 1 operator
One operator per statement is too many operators for a real canvas. The MVP coarsening rule is intentionally simple:
So the whole MVP surface is:
compile(source)→ P⊥, andcompile(source, group=N)→ the same program as ⌈lines/N⌉-ish fused operators. Both outputs run, and both are verified against the original script.What the MVP requires of the input
To make "one statement = one operator" well-defined, a small normalization front-end runs first (all source-to-source, behavior-preserving): comprehensions become loops, functions are inlined toward the main body, and
globalstate is rewritten into explicit parameter/return threading so every dependency between two lines is a visible variable. Scripts using features outside that subset are rejected rather than miscompiled.Non-goals (for this MVP)
Questions for discussion
Beta Was this translation helpful? Give feedback.
All reactions