File size: 1,811 Bytes
0f5d220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Recreate the audited Linux x86_64/Python 3.11.13 common environment."""
import argparse,hashlib,json,os,pathlib,subprocess,sys

def main():
    p=argparse.ArgumentParser();p.add_argument('--openpi-source',required=True);p.add_argument('--venv',default='.release_local/venv');a=p.parse_args()
    root=pathlib.Path(__file__).resolve().parents[1];source=pathlib.Path(a.openpi_source).resolve();venv=pathlib.Path(a.venv).resolve();env={**os.environ,'UV_LINK_MODE':'copy'}
    revision=subprocess.check_output(['git','-C',str(source),'rev-parse','HEAD'],text=True).strip()
    if revision!='215abfb217dbac7d5f1273282331b9b1866c0479':raise ValueError('Unvalidated source revision')
    python=venv/'bin/python'
    if not python.exists():subprocess.run(['uv','venv','--python','3.11.13',str(venv)],env=env,check=True)
    version=subprocess.check_output([str(python),'-c','import platform;print(platform.python_version())'],text=True).strip()
    if version!='3.11.13':raise ValueError('Expected a dedicated Python 3.11.13 environment')
    subprocess.run(['uv','pip','install','--python',str(python),'-r',str(root/'configs/environment-linux-cu126.txt')],env=env,check=True)
    replacement=source/'src/openpi/models_pytorch/transformers_replace'
    code='''import hashlib,json,pathlib,shutil,transformers,sys
source=pathlib.Path(sys.argv[1]);dest=pathlib.Path(transformers.__file__).parent
rows=[]
for f in source.rglob('*.py'):
 p=dest/f.relative_to(source);p.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(f,p)
 h=hashlib.sha256(p.read_bytes()).hexdigest();assert h==hashlib.sha256(f.read_bytes()).hexdigest();rows.append(dict(path=str(p),sha256=h))
print(json.dumps(rows,indent=2))
'''
    subprocess.run([str(python),'-c',code,str(replacement)],env=env,check=True)

if __name__=='__main__':main()