import os import subprocess from pathlib import Path PIXI_PATH = Path("/home/user/.pixi/bin/pixi") PIXI_VERSION = "0.59.0" MOCK_CUDA_VERSION = "12.9" # Pretend CUDA 12.9 is available so pixi can solve environments on machines without GPUs. os.environ.setdefault("CONDA_OVERRIDE_CUDA", MOCK_CUDA_VERSION) def check_and_install_pixi() -> None: try: subprocess.check_call(f"{PIXI_PATH} --version", shell=True) except subprocess.CalledProcessError: print("pixi not found. Installing pixi...") # Install pixi using the provided installation script subprocess.check_call( f"PIXI_VERSION=v{PIXI_VERSION} curl -fsSL https://pixi.sh/install.sh | bash", shell=True, ) subprocess.check_call(f"{PIXI_PATH} self-update --version {PIXI_VERSION}", shell=True) subprocess.check_call(f"{PIXI_PATH} --version", shell=True) def run_command(command: str) -> None: try: subprocess.check_call(command, shell=True) except subprocess.CalledProcessError as e: print(f"run command {command}. Error: {e}") if __name__ == "__main__": check_and_install_pixi() # install lsof # run_command(command=f"{PIXI_PATH} global install lsof") # # kill anything running on port 7860 # run_command(command=f"{PIXI_PATH.parent}/lsof -t -i:7860 | xargs -r kill") # clean current environment run_command(command=f"{PIXI_PATH} clean") # run spaces app run_command(command=f"{PIXI_PATH} run app")