-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathupdate_project_schema.py
53 lines (39 loc) · 1.43 KB
/
update_project_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""
A utility script to update the project schema in multiple files.
simply run `python update_project_schema.py <version>` to update the version in the files.
"""
from dataclasses import dataclass
from pathlib import Path
from typing import Callable
@dataclass(frozen=True, slots=True)
class Location:
relative_path: Path
# length, width
template: Callable[[int], str]
LOCATIONS: list[Location] = [
# Choreo UI
Location(
relative_path=Path("src/document/2025/ProjectSchemaVersion.ts"),
template=lambda version: f"""// Auto-generated by update_project_schema.py
export const PROJECT_SCHEMA_VERSION = {version};""",
),
# Choreo backend
Location(
relative_path=Path("src-core/src/spec/project_schema_version.rs"),
template=lambda version: f"""// Auto-generated by update_project_schema.py
pub const PROJECT_SCHEMA_VERSION: u32 = {version};""",
),
]
def update_version(version: int) -> None:
for location in LOCATIONS:
file_path = Path(__file__).parent / location.relative_path
with open(file_path, "w") as f:
f.write(location.template(version))
f.write("\n")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Update version in files")
parser.add_argument("version", type=int, help="Project schema version")
args = parser.parse_args()
update_version(args.version)