Split the previous monolithic implementation into focused modules for CLI handling, workflow loading, runtime bootstrap, load ordering, planning, rendering, and file I/O. Keep the public compatibility surface intact by preserving the legacy top-level wrapper while adding as the documented entrypoint. This reduces cross-cutting coupling inside the exporter and makes the runtime/bootstrap behavior easier to evolve without carrying unrelated concerns in one file.
24 lines
800 B
Python
24 lines
800 B
Python
import json
|
|
import os
|
|
from typing import TextIO
|
|
|
|
|
|
def load_json_input(file_path: str | TextIO, encoding: str = "utf-8") -> dict:
|
|
"""Read workflow JSON from a file path or file-like object."""
|
|
if hasattr(file_path, "read"):
|
|
return json.load(file_path)
|
|
with open(file_path, "r", encoding=encoding) as file:
|
|
return json.load(file)
|
|
|
|
|
|
def write_python_output(file_path: str | TextIO, code: str) -> None:
|
|
"""Write generated Python to a file path or file-like object."""
|
|
if isinstance(file_path, str):
|
|
directory = os.path.dirname(file_path)
|
|
if directory and not os.path.exists(directory):
|
|
os.makedirs(directory)
|
|
with open(file_path, "w", encoding="utf-8") as file:
|
|
file.write(code)
|
|
return
|
|
file_path.write(code)
|