Files
leleka/scripts/dev/rename_strata_names.py
T

63 lines
2.7 KiB
Python

"""Stage 9 of docs/experiments/plan-faster-than-strata.md: the historical Strata names in our own code become ours.
strata-next -> leleka-api (the gateway binary of control-plane/)
strata-control -> leleka-control-plane (the crate of control-plane/)
strata-desktop-core -> leleka-engine-host (the crate of desktop-core/: it hosts the engine process leleka-inference
and the node, pool and gateway services around it)
The `STRATA_*` environment variables stay (the language shared with the Original). Not touched: `engine/strata` (the
Original, including its Python package `strata_control`), the experiment records and measured data, `*.patch` files and
`docs/upstream/` (diffs against the Original), `Cargo.lock` (regenerate it with `cargo metadata --offline`).
The underscore forms (`strata_control`, `strata_desktop_core`) are the crate identifiers and change in `.rs` and `.toml`
files only. Usage: python scripts/dev/rename_strata_names.py [--dry-run]
"""
import pathlib
import subprocess
import sys
SKIP_PREFIXES = (
"engine/strata/", "experiments/", "artifacts/", "docs/experiments/", "docs/e2e-data/", "benchmarks/e2e-data/", "docs/upstream/",
"docs/ledger", "Cargo.lock", "scripts/dev/rename_strata_names.py",
)
HYPHEN = (("strata-next", "leleka-api"), ("strata-control", "leleka-control-plane"),
("strata-desktop-core", "leleka-engine-host"))
UNDERSCORE = (("strata_control", "leleka_control_plane"), ("strata_desktop_core", "leleka_engine_host"))
KEEP = "<!-- old-names -->" # a line that documents the old names (the table in tech-debt.md) is left as it is
def rename(line, name):
for old, to in HYPHEN:
line = line.replace(old, to)
if name.endswith((".rs", ".toml")):
for old, to in UNDERSCORE:
line = line.replace(old, to)
return line
def main():
dry = "--dry-run" in sys.argv
root = pathlib.Path(__file__).resolve().parents[2]
files = subprocess.run(["git", "ls-files"], cwd=root, capture_output=True, text=True, check=True).stdout.splitlines()
changed = 0
for name in files:
if name.startswith(SKIP_PREFIXES) or name.endswith(".patch"):
continue
path = root / name
try:
raw = path.read_bytes()
text = raw.decode("utf-8")
except (UnicodeDecodeError, OSError):
continue
new = "\n".join(line if KEEP in line else rename(line, name) for line in text.split("\n"))
if new != text:
changed += 1
if not dry:
path.write_bytes(new.encode("utf-8"))
print(f"{changed} files {'would change' if dry else 'changed'}")
if __name__ == "__main__":
main()