-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
100 lines (78 loc) · 3.12 KB
/
setup.py
File metadata and controls
100 lines (78 loc) · 3.12 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Fetches the MEOS public headers and PostgreSQL stub headers from the
# MobilityDB GitHub repository, then wires them into the expected layout.
# Usage:
# python setup.py # uses the default branch (master)
# python setup.py --branch v1.2.0 # pin to a specific tag or branch
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
REPO_URL = "https://github.com/MobilityDB/MobilityDB"
CLONE_DIR = Path("_mobilitydb")
MEOS_INCLUDE_SRC = CLONE_DIR / "meos" / "include"
POSTGRES_SRC = CLONE_DIR / "postgres"
MEOS_INCLUDE_DST = Path("meos") / "include"
POSTGRES_LINK = Path("meos") / "postgres"
CUSTOM_STUBS = {"pg_config.h", "postgres_int_defs.h", "postgres_ext_defs.in.h"}
def run(cmd: list[str]) -> None:
print(f" $ {' '.join(cmd)}")
subprocess.run(cmd, check=True)
def step_clone(branch: str) -> None:
print(f"[1/3] Cloning MobilityDB (branch: {branch})...")
if CLONE_DIR.exists():
print(f" {CLONE_DIR}/ already exists, updating...")
run(["git", "-C", str(CLONE_DIR), "fetch", "--depth=1", "origin", branch])
run(["git", "-C", str(CLONE_DIR), "reset", "--hard", f"origin/{branch}"])
else:
run([
"git", "clone",
"--depth", "1",
"--filter=blob:none",
"--sparse",
"--branch", branch,
REPO_URL,
str(CLONE_DIR),
])
run(["git", "-C", str(CLONE_DIR), "sparse-checkout", "set", "meos/include", "postgres"])
print(f" Done.")
def step_sync_headers() -> None:
print("[2/3] Syncing MEOS public headers...")
MEOS_INCLUDE_DST.mkdir(parents=True, exist_ok=True)
copied = []
for src in MEOS_INCLUDE_SRC.glob("*.h"):
if src.name in CUSTOM_STUBS:
continue
dst = MEOS_INCLUDE_DST / src.name
shutil.copy2(src, dst)
copied.append(src.name)
if copied:
for name in copied:
print(f" → meos/include/{name}")
else:
print(" No headers to copy.")
def step_symlink() -> None:
print("[3/3] Setting up meos/postgres symlink...")
if POSTGRES_LINK.is_symlink():
POSTGRES_LINK.unlink()
elif POSTGRES_LINK.exists():
print(f"Error: {POSTGRES_LINK} exists and is not a symlink. Remove it manually.", file=sys.stderr)
sys.exit(1)
target = POSTGRES_SRC.resolve()
if not target.exists():
print(f"Error: expected postgres headers at {target}", file=sys.stderr)
sys.exit(1)
POSTGRES_LINK.symlink_to(target)
print(f" → meos/postgres -> {target}")
def main() -> None:
parser = argparse.ArgumentParser(description="Set up MEOS headers from MobilityDB GitHub.")
parser.add_argument("--branch", default="master", metavar="BRANCH",
help="Branch or tag to clone (default: master)")
args = parser.parse_args()
print(f"Setting up MEOS IDL Generator...\n")
step_clone(args.branch)
step_sync_headers()
step_symlink()
print(f"\nAll done. Run `python run.py` to generate output/meos-idl.json.")
if __name__ == "__main__":
main()