"""Clone and extract reviewed-source candidates into a new isolated research folder. Does not execute cloned source or modify global git configuration. """ import json,subprocess from pathlib import Path ROOT=Path(__file__).resolve().parents[1] for source in json.loads((ROOT/'RESEARCH_SOURCES.json').read_text()): key=source['repo'].split('/')[-1].lower();target=ROOT/'work/upstream'/key if not target.exists():subprocess.run(['git','clone','--filter=blob:none','--no-checkout','https://github.com/'+source['repo']+'.git',str(target)],check=True) subprocess.run(['git','-C',str(target),'fetch','--depth','1','origin',source['commit']],check=True) files=subprocess.check_output(['git','-C',str(target),'ls-tree','--name-only','-r',source['commit']],text=True).splitlines() for filename in files: if not filename.endswith(('.py','.md','.toml')) and 'LICENSE' not in filename:continue body=subprocess.check_output(['git','-C',str(target),'show',source['commit']+':'+filename]) destination=target/filename;destination.parent.mkdir(parents=True,exist_ok=True);destination.write_bytes(body) print('Source ready',source['repo'],source['commit'])