okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ef8071303
main
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 (): 12parser = argparse .ArgumentParser (description = __doc__ ) 13parser .add_argument ('--root' ,type = Path ,required = True ) 14parser .add_argument ('--repo' ,type = Path ,default = HERE .parents [2 ]) 15args = parser .parse_args () 16repo ,root = args .repo .resolve (),args .root .resolve () 17layout = json .loads ((HERE / 'source-layout.json' ).read_text ()) 18for spec in layout .values (): 19if not isinstance (spec ,dict )or 'commit' not in spec : 20continue 21dst = root / spec ['path' ] 22if dst .exists (): 23actual = subprocess .check_output (['git' ,'-C' ,str (dst ),'rev-parse' ,'HEAD' ],text = True ).strip () 24if actual != spec ['commit' ]: 25raise RuntimeError (f' { dst } exists at a different commit; choose another --root' ) 26continue 27dst .parent .mkdir (parents = True ,exist_ok = True ) 28if spec .get ('repository' ): 29subprocess .run (['git' ,'clone' ,'--no-checkout' ,spec ['repository' ],str (dst )],check = True ) 30subprocess .run (['git' ,'-C' ,str (dst ),'checkout' ,'--detach' ,spec ['commit' ]],check = True ) 31else : 32subprocess .run (['git' ,'-C' ,str (repo ),'worktree' ,'add' ,'--detach' ,str (dst ),spec ['commit' ]],check = True ) 33'Pinned sources prepared. Follow README for packages, artifacts, builds and API startup.' ) 34 35 36if __name__ == '__main__' : 37main ()