-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_schemas.py
More file actions
54 lines (47 loc) · 1.44 KB
/
Copy pathsync_schemas.py
File metadata and controls
54 lines (47 loc) · 1.44 KB
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
54
#!/usr/bin/env python3
"""Copy the canonical consumer schemas into the Python distribution, or check for drift."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
SCHEMA_FILES = (
"signed-document.schema.json",
"release-manifest.schema.json",
"box-manifest.schema.json",
"target.schema.json",
"execution.schema.json",
)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true")
options = parser.parse_args()
repo_root = Path(__file__).resolve().parents[2]
source_root = repo_root / "src" / "contract" / "schema"
destination_root = (
repo_root
/ "python"
/ "src"
/ "scrollcase_consumer"
/ "schemas"
)
destination_root.mkdir(parents=True, exist_ok=True)
drift: list[str] = []
for name in SCHEMA_FILES:
source = (source_root / name).read_bytes()
destination = destination_root / name
if options.check:
if not destination.exists() or destination.read_bytes() != source:
drift.append(name)
else:
destination.write_bytes(source)
if drift:
print(
"Python schema copies are stale: "
+ ", ".join(drift)
+ ". Run python scripts/sync_schemas.py.",
file=sys.stderr,
)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())