Spaces:
Runtime error
Runtime error
| import re | |
| import subprocess | |
| from pathlib import Path | |
| PIXI_PATH = Path("/home/user/.pixi/bin/pixi") | |
| PIXI_VERSION = "0.44.0" | |
| def check_and_install_pixi() -> None: | |
| try: | |
| # Check if pixi is installed and get its version | |
| result = subprocess.run(f"{PIXI_PATH} --version", shell=True, capture_output=True, text=True) | |
| if result.returncode == 0: | |
| installed_version = result.stdout.strip() | |
| # Extract version number using regex | |
| version_match = re.search(r"(\d+\.\d+\.\d+)", installed_version) | |
| if version_match and version_match.group(1) == PIXI_VERSION: | |
| print(f"Correct pixi version {PIXI_VERSION} is already installed.") | |
| else: | |
| extracted_version = version_match.group(1) if version_match else "unknown" | |
| print(f"Incorrect pixi version: {extracted_version}. Required: {PIXI_VERSION}") | |
| print(f"Updating pixi to version {PIXI_VERSION}...") | |
| subprocess.check_call(f"{PIXI_PATH} self-update --version {PIXI_VERSION}", shell=True) | |
| subprocess.check_call(f"{PIXI_PATH} --version", shell=True) | |
| else: | |
| raise subprocess.CalledProcessError(returncode=result.returncode, cmd=result.args) | |
| 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") | |
| # run spaces app | |
| run_command(command=f"{PIXI_PATH} run -e spaces app") | |