refactor(clew): rename object dump to AST dump

This commit is contained in:
2026-09-07 18:19:54 -04:00
parent 4c12f23a15
commit 774686d614
3 changed files with 19 additions and 19 deletions

View File

@@ -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"],
)

View File

@@ -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__":

View File

@@ -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)