File size: 1,341 Bytes
798e018
 
 
 
0c433b9
798e018
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e97be2
 
798e018
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import subprocess
from pathlib import Path

PIXI_PATH = Path("/home/user/.pixi/bin/pixi")
PIXI_VERSION = "0.32.1"


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 -e spaces app")