15 lines
994 B
Python
15 lines
994 B
Python
"""Expose only immutable CUDA packages, never another application's full environment."""
|
|
import json,subprocess
|
|
from pathlib import Path
|
|
PREFIXES=('torchgen','functorch','torch','torchaudio','triton','nvidia','cuda','cuda_bindings','cuda_python')
|
|
def share_cuda(python,base,shared,command):
|
|
roots=json.loads(subprocess.check_output([str(shared),'-c','import json,site;print(json.dumps(site.getsitepackages()))'],text=True))
|
|
destination=Path(base)/'cuda-packages';destination.mkdir(exist_ok=True)
|
|
for root in roots:
|
|
if not Path(root).is_dir():continue
|
|
for path in Path(root).iterdir():
|
|
if any(path.name==p or path.name.startswith(p+'-') or path.name.startswith(p+'_') for p in PREFIXES):
|
|
target=destination/path.name
|
|
if not target.exists():target.symlink_to(path.resolve(),target_is_directory=path.is_dir())
|
|
command([python,'-c','import site,sys;from pathlib import Path;Path(site.getsitepackages()[0],"deck-shared-cuda.pth").write_text(sys.argv[1]+"\\n")',str(destination)])
|