okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221terminal archive: bundled Python for Windows x64 and Linux x86_64, hash-locked wheels, launchers, smoke test66bc88907

main
4.1 KiB76 linesraw
1#!/bin/sh
2# Strata for Linux: the first run installs everything and starts the model; later runs just start it.
3# Needs only an NVIDIA driver (or, for an AMD Radeon card, the kernel's amdgpu driver: see docs/AMD_HIP.md).
4# Python (with venv) is installed through apt/dnf if it is missing (asks for sudo).
5# NixOS (or STRATA_UV=1) with uv installed: uv makes the project venv; every other Linux uses the standard venv.
6cd "$(dirname "$0")" || exit 1
7# A bundled Python runtime (the python/ folder of the terminal archive) is used when it is there: nothing to find,
8# install or download. update.sh runs this file, so it uses it too.
9if [ -x python/bin/python3 ]; then
10  PYTHONNOUSERSITE=1; export PYTHONNOUSERSITE
11  unset PYTHONHOME PYTHONPATH
12  exec python/bin/python3 setup.py "$@"
13fi
14# Python 3.10+ that can make a venv WITH pip: Debian/Ubuntu ship `venv` without `ensurepip` (that is the separate
15# python3-venv package), and a venv made without it has no pip
16ok_py() { "$1" -c 'import sys, venv, ensurepip; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; }
17# a .venv from an earlier run that failed half-way has a python but no pip: start it again
18if [ -x .venv/bin/python ] && ! .venv/bin/python -m pip --version >/dev/null 2>&1; then
19  rm -rf .venv
20fi
21if [ ! -x .venv/bin/python ]; then
22  # uv's own Python only on NixOS (its Python cannot load pip wheels' libraries), or when asked: STRATA_UV=1.
23  # Everywhere else the standard venv stays the default (#662: a silent toolchain change was not wanted).
24  UV=""
25  if [ "${STRATA_UV:-}" = "1" ] || grep -qi '^ID=nixos' /etc/os-release 2>/dev/null; then
26    UV="$(command -v uv 2>/dev/null || true)"
27  fi
28  PY=""
29  if [ -n "$UV" ]; then
30    # Prefer uv's own interpreter: unlike Nix's Python, it works naturally with pip wheels using dlopen.
31    PY=3.12
32  else
33    for c in python3 python; do
34      if command -v $c >/dev/null 2>&1 && ok_py $c; then
35        PY=$c; break
36      fi
37    done
38  fi
39  # macOS: the system Python is 3.9; a standalone Python 3.12 goes into .python (no sudo, no Homebrew; pinned)
40  if [ -z "$PY" ] && [ "$(uname -s)" = Darwin ]; then
41    if [ ! -x .python/python/bin/python3 ]; then
42      PBS="https://github.com/astral-sh/python-build-standalone/releases/download/20261009/cpython-3.12.15%2B20261009-aarch64-apple-darwin-install_only.tar.gz"
43      echo "Python 3.10+ is needed; downloading a standalone Python 3.12 into .python (25 MB) ..."
44      mkdir -p .python && curl -fL --retry 3 -o .python/python.tar.gz "$PBS" || { echo "could not download Python"; exit 1; }
45      if [ "$(shasum -a 256 .python/python.tar.gz | cut -d" " -f1)" != "83dcb04777c798bd95f3687acf9ae84b09860272ee6bdfb05be8bcf9447f75b8" ]; then
46        rm -f .python/python.tar.gz; echo "the Python download does not match its pinned SHA-256"; exit 1
47      fi
48      tar xzf .python/python.tar.gz -C .python && rm -f .python/python.tar.gz
49    fi
50    PY=.python/python/bin/python3
51  fi
52  if [ -z "$PY" ]; then
53    echo "Python 3.10+ with venv is needed; installing it (sudo will ask for your password) ..."
54    if command -v apt-get >/dev/null 2>&1; then
55      sudo apt-get update && sudo apt-get install -y python3 python3-venv python3-pip
56    elif command -v dnf >/dev/null 2>&1; then
57      sudo dnf install -y python3 python3-pip
58    elif command -v pacman >/dev/null 2>&1; then
59      sudo pacman -S --noconfirm python python-pip
60    fi
61    PY=python3
62    if ! ok_py $PY; then
63      echo "Please install Python 3.10 or newer with venv (Ubuntu/Debian: sudo apt install python3-venv), then run"
64      echo "./setup.sh again. On NixOS, add uv to environment.systemPackages."
65      exit 1
66    fi
67  fi
68  if [ -n "$UV" ]; then
69    # Force an uv-managed interpreter: pip wheels may dlopen libraries outside the Nix store.
70    "$UV" venv --managed-python --seed --python "$PY" .venv || { echo "Could not create the uv environment in .venv."; exit 1; }
71  else
72    # a private environment inside this folder (system Python stays untouched; newer distros refuse global pip)
73    $PY -m venv .venv || { rm -rf .venv; echo "could not create .venv: sudo apt install python3-venv"; exit 1; }
74  fi
75fi
76exec .venv/bin/python setup.py "$@"