From 774686d6149be2c3ed18f11748563f391c369a76 Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 7 Sep 2026 18:19:54 -0400 Subject: [PATCH] refactor(clew): rename object dump to AST dump --- src/clew/BUILD.bazel | 6 ++--- src/clew/clew.py | 26 +++++++++---------- .../{renpy_object_dump.py => dump_ast.py} | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) rename src/clew/{renpy_object_dump.py => dump_ast.py} (97%) diff --git a/src/clew/BUILD.bazel b/src/clew/BUILD.bazel index 883ce44..59d121f 100644 --- a/src/clew/BUILD.bazel +++ b/src/clew/BUILD.bazel @@ -5,12 +5,12 @@ py_binary( srcs = ["clew.py"], main = "clew.py", deps = [ - ":renpy_object_dump", + ":dump_ast", "//third_party/python:rpycdec", ], ) py_library( - name = "renpy_object_dump", - srcs = ["renpy_object_dump.py"], + name = "dump_ast", + srcs = ["dump_ast.py"], ) diff --git a/src/clew/clew.py b/src/clew/clew.py index 2fbbbea..8f1ee7d 100644 --- a/src/clew/clew.py +++ b/src/clew/clew.py @@ -11,7 +11,7 @@ from collections.abc import Callable from pathlib import Path from rpycdec.rpa import extract_rpa -from src.clew import renpy_object_dump +from src.clew import dump_ast as dump_ast_script LOG = logging.getLogger(__name__) @@ -38,9 +38,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace: help="Replace Clew-managed output directories.", ) parser.add_argument( - "--no-renpy-object-dump", + "--no-ast-dump", action="store_true", - help="Skip dumping compiled Ren'Py scripts from output/extracted/ to output/ast-raw/.", + help="Skip dumping compiled scripts from output/extracted/ to output/ast-raw/.", ) return parser.parse_args(argv) @@ -98,14 +98,14 @@ def find(root: Path, predicate: Callable[[Path], bool]) -> list[Path]: return sorted(matches) -def object_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path: +def ast_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path: namespace = game_root.relative_to(extracted_root) relative_script = script.relative_to(game_root) return output_root / "ast-raw" / namespace / relative_script.with_suffix(relative_script.suffix + ".json") -def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None: - exporter = Path(renpy_object_dump.__file__).resolve() +def run_ast_dump(game_root: Path, script: Path, output: Path) -> None: + exporter = Path(dump_ast_script.__file__).resolve() bundled_python = game_root / "lib" / "linux-x86_64" / "python" output.parent.mkdir(parents=True, exist_ok=True) command = [ @@ -122,7 +122,7 @@ def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None: subprocess.run(command, check=True) -def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool) -> None: +def dump_ast(output_root: Path, extracted_root: Path, overwrite: bool) -> None: game_roots = find( extracted_root, lambda path: ( @@ -143,12 +143,12 @@ def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool) LOG.info("found %d compiled Ren'Py scripts under %s", len(scripts), game_root) total = len(scripts) for index, script in enumerate(scripts, start=1): - output = object_dump_output_path(output_root, extracted_root, game_root, script) + output = ast_dump_output_path(output_root, extracted_root, game_root, script) if output.exists() and not overwrite: - LOG.info("skipping existing Ren'Py object dump %d/%d: %s", index, total, output) + LOG.info("skipping existing AST dump %d/%d: %s", index, total, output) continue - LOG.info("dumping Ren'Py object graph %d/%d: %s", index, total, script) - run_renpy_object_dump(game_root, script, output) + LOG.info("dumping AST %d/%d: %s", index, total, script) + run_ast_dump(game_root, script, output) def run(args: argparse.Namespace) -> None: @@ -162,8 +162,8 @@ def run(args: argparse.Namespace) -> None: extracted = get_output_directory(output_root, "extracted") extract_game_files(game_root, extracted) - if not args.no_renpy_object_dump: - dump_renpy_objects(output_root, extracted, args.overwrite) + if not args.no_ast_dump: + dump_ast(output_root, extracted, args.overwrite) if __name__ == "__main__": diff --git a/src/clew/renpy_object_dump.py b/src/clew/dump_ast.py similarity index 97% rename from src/clew/renpy_object_dump.py rename to src/clew/dump_ast.py index f89b6c3..c2b3128 100644 --- a/src/clew/renpy_object_dump.py +++ b/src/clew/dump_ast.py @@ -24,13 +24,13 @@ except NameError: RPYC2_HEADER = b"RENPY RPC2" -SCHEMA = "clew-renpy-object-dump-v1" +SCHEMA = "clew-ast-dump-v1" def parse_args(argv): parser = argparse.ArgumentParser( - prog="renpy-object-dump", - description="Dump Ren'Py compiled script objects as generic JSON.", + prog="dump-ast", + description="Dump compiled Ren'Py script ASTs as generic JSON.", ) parser.add_argument("--game-root", required=True) parser.add_argument("--input", required=True)