okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-141-fixb: Python, docs and bench fixes and portsef8071303

main
1.6 KiB37 linesraw
1#!/usr/bin/env python3
2"""Create pinned source worktrees; does not install packages, build or start a model."""
3import argparse
4import json
5from pathlib import Path
6import subprocess
7
8HERE = Path(__file__).resolve().parent
9
10
11def main():
12    parser = argparse.ArgumentParser(description=__doc__)
13    parser.add_argument('--root', type=Path, required=True)
14    parser.add_argument('--repo', type=Path, default=HERE.parents[2])
15    args = parser.parse_args()
16    repo, root = args.repo.resolve(), args.root.resolve()
17    layout = json.loads((HERE / 'source-layout.json').read_text())
18    for spec in layout.values():
19        if not isinstance(spec, dict) or 'commit' not in spec:
20            continue
21        dst = root / spec['path']
22        if dst.exists():
23            actual = subprocess.check_output(['git', '-C', str(dst), 'rev-parse', 'HEAD'], text=True).strip()
24            if actual != spec['commit']:
25                raise RuntimeError(f'{dst} exists at a different commit; choose another --root')
26            continue
27        dst.parent.mkdir(parents=True, exist_ok=True)
28        if spec.get('repository'):
29            subprocess.run(['git', 'clone', '--no-checkout', spec['repository'], str(dst)], check=True)
30            subprocess.run(['git', '-C', str(dst), 'checkout', '--detach', spec['commit']], check=True)
31        else:
32            subprocess.run(['git', '-C', str(repo), 'worktree', 'add', '--detach', str(dst), spec['commit']], check=True)
33    print('Pinned sources prepared. Follow README for packages, artifacts, builds and API startup.')
34
35
36if __name__ == '__main__':
37    main()