25 lines
2.1 KiB
Python
25 lines
2.1 KiB
Python
"""Profile-local, checksum-verified Python; no Hermes-environment mutation."""
|
|
import hashlib,json,os,shutil,subprocess,tarfile,urllib.request
|
|
from pathlib import Path
|
|
os.nice(10)
|
|
p=Path('/opt/data/profiles/jean-luc-picode');base=p/'toolchains';cache=p/'cache/downloads'
|
|
cache.mkdir(parents=True,exist_ok=True)
|
|
url='https://github.com/astral-sh/python-build-standalone/releases/download/20261021/cpython-3.12.15%2B20261021-x86_64-unknown-linux-gnu-install_only.tar.gz'
|
|
digest='5ff9f0602ce964a529ed1e8555d3abab6341926d724402ba9a15e9e877191124'
|
|
archive=cache/'cpython-3.12.15.tar.gz'
|
|
if not (base/'python/bin/python3.12').exists():
|
|
with urllib.request.urlopen(urllib.request.Request(url,headers={'User-Agent':'Jean-Luc-Picode/1.0'}),timeout=90) as r,archive.open('wb') as f:shutil.copyfileobj(r,f)
|
|
assert hashlib.sha256(archive.read_bytes()).hexdigest()==digest,'Python checksum mismatch'
|
|
with tarfile.open(archive) as t:t.extractall(base,filter='data')
|
|
python=base/'python/bin/python3.12';venv=p/'venvs/development'
|
|
env={k:v for k,v in os.environ.items() if k not in {'PYTHONHOME','PYTHONPATH'}}
|
|
env.update({'HOME':str(p/'home'),'PYTHONNOUSERSITE':'1','PYTHONDONTWRITEBYTECODE':'1'})
|
|
if not (venv/'bin/python').exists():subprocess.run([str(python),'-m','venv',str(venv)],check=True,env=env)
|
|
versions={'python':{'version':subprocess.check_output([str(python),'--version'],text=True).strip(),'source':url,'sha256':digest},'dependencies':'Base Python only; project packages and SDKs are installed per selected project' ,'image_tools':{}}
|
|
for name,args in [('node',['node','--version']),('openssl',['openssl','version']),('git',['git','--version']),('bash',['bash','--version'])]:
|
|
versions['image_tools'][name]={'path':shutil.which(name),'version':subprocess.check_output(args,text=True).splitlines()[0]}
|
|
(base/'versions.json').write_text(json.dumps(versions,indent=2)+'\n')
|
|
(base/'requirements-development.lock.txt').write_text(subprocess.check_output([str(venv/'bin/python'),'-m','pip','freeze'],text=True,env=env))
|
|
if archive.exists():archive.unlink()
|
|
print(json.dumps(versions),flush=True)
|