From 8faed57ff873cf91826a58d4f7fc6e8adf650e1b Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 7 Sep 2026 18:33:02 -0400 Subject: [PATCH] refactor(clew): flatten Ren'Py AST extraction --- src/clew/clew.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/clew/clew.py b/src/clew/clew.py index 07a6b3b..0005c59 100644 --- a/src/clew/clew.py +++ b/src/clew/clew.py @@ -104,18 +104,22 @@ def ast_dump_output_path(output_root: Path, extracted_root: Path, game_root: Pat return output_root / "ast" / namespace / relative_script.with_suffix(relative_script.suffix + ".json") -def run_extract_renpy_ast(game_root: Path, script: Path, output: Path) -> None: - exporter = Path(dump_ast_script.__file__).resolve() - bundled_python = game_root / "lib" / "linux-x86_64" / "python" +def run_extract_renpy_ast( + bundled_python: Path, + extractor: Path, + game_root: Path, + compiled_script: Path, + output: Path, +) -> None: output.parent.mkdir(parents=True, exist_ok=True) command = [ "steam-run", str(bundled_python), - str(exporter), + str(extractor), "--game-root", str(game_root), "--input", - str(script), + str(compiled_script), "--output", str(output), ] @@ -123,6 +127,7 @@ def run_extract_renpy_ast(game_root: Path, script: Path, output: Path) -> None: def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) -> None: + extractor = Path(dump_ast_script.__file__).resolve() game_roots = find( extracted_root, lambda path: ( @@ -136,6 +141,7 @@ def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) - return for game_root in game_roots: + bundled_python = game_root / "lib" / "linux-x86_64" / "python" scripts = find( game_root / "game", lambda path: path.is_file() and path.suffix.lower() in {".rpyc", ".rpymc"}, @@ -147,7 +153,7 @@ def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) - LOG.info("skipping existing AST dump: %s", output) continue LOG.info("dumping AST: %s", script) - run_extract_renpy_ast(game_root, script, output) + run_extract_renpy_ast(bundled_python, extractor, game_root, script, output) def run(args: argparse.Namespace) -> None: