fix(install): provision supported Python from TUR on Termux and update docs
This commit is contained in:
1
contributors/emails/hello@augustinbrun.com
Normal file
1
contributors/emails/hello@augustinbrun.com
Normal file
@@ -0,0 +1 @@
|
||||
gustbr
|
||||
@@ -639,15 +639,43 @@ check_python() {
|
||||
log_info "Installing Python via pkg..."
|
||||
pkg install -y python >/dev/null
|
||||
PYTHON_PATH="$(command -v python)"
|
||||
if ! "$PYTHON_PATH" -c 'import sys; raise SystemExit(0 if (3, 11) <= sys.version_info[:2] < (3, 14) else 1)' 2>/dev/null; then
|
||||
PYTHON_FOUND_VERSION="$("$PYTHON_PATH" --version 2>/dev/null || true)"
|
||||
log_error "Termux Python $PYTHON_FOUND_VERSION is not supported; Hermes requires Python >=3.11,<3.14"
|
||||
log_info "Install a compatible Termux Python (for example python3.11) and re-run this script"
|
||||
exit 1
|
||||
if "$PYTHON_PATH" -c 'import sys; raise SystemExit(0 if (3, 11) <= sys.version_info[:2] < (3, 14) else 1)' 2>/dev/null; then
|
||||
PYTHON_FOUND_VERSION="$("$PYTHON_PATH" --version 2>/dev/null)"
|
||||
log_success "Python installed: $PYTHON_FOUND_VERSION"
|
||||
return 0
|
||||
fi
|
||||
PYTHON_FOUND_VERSION="$("$PYTHON_PATH" --version 2>/dev/null)"
|
||||
log_success "Python installed: $PYTHON_FOUND_VERSION"
|
||||
return 0
|
||||
|
||||
# Termux's default `python` package is outside the supported range
|
||||
# (e.g. 3.14.x before Rust transitives ship cp314 wheels). The Termux
|
||||
# User Repository (TUR) publishes versioned CPython packages
|
||||
# (python3.13, python3.11), so try to provision a supported
|
||||
# interpreter from there before giving up.
|
||||
PYTHON_FOUND_VERSION="$("$PYTHON_PATH" --version 2>/dev/null || true)"
|
||||
log_warn "Termux Python $PYTHON_FOUND_VERSION is outside the supported range (>=3.11,<3.14)"
|
||||
log_info "Trying the Termux User Repository (TUR) for a supported Python..."
|
||||
pkg install -y tur-repo >/dev/null 2>&1 || true
|
||||
local tur_pkg
|
||||
for tur_pkg in python3.13 python3.12 python3.11; do
|
||||
if ! pkg install -y "$tur_pkg" >/dev/null 2>&1; then
|
||||
continue
|
||||
fi
|
||||
if ! command -v "$tur_pkg" >/dev/null 2>&1; then
|
||||
continue
|
||||
fi
|
||||
local tur_path
|
||||
tur_path="$(command -v "$tur_pkg")"
|
||||
if "$tur_path" -c 'import sys; raise SystemExit(0 if (3, 11) <= sys.version_info[:2] < (3, 14) else 1)' 2>/dev/null; then
|
||||
PYTHON_PATH="$tur_path"
|
||||
PYTHON_FOUND_VERSION="$("$PYTHON_PATH" --version 2>/dev/null)"
|
||||
log_success "Python installed from TUR: $PYTHON_FOUND_VERSION"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
log_error "Termux Python $PYTHON_FOUND_VERSION is not supported; Hermes requires Python >=3.11,<3.14"
|
||||
log_info "Install a supported interpreter and re-run this script:"
|
||||
log_info " pkg install tur-repo && pkg install python3.13"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Checking Python $PYTHON_VERSION..."
|
||||
|
||||
@@ -153,7 +153,8 @@ if is_termux; then
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
PYTHON_FOUND_VERSION="$(python --version 2>/dev/null || true)"
|
||||
echo -e "${RED}✗${NC} Termux Python $PYTHON_FOUND_VERSION is not supported; Hermes requires Python >=3.11,<3.14"
|
||||
echo " Install a compatible Termux Python (for example python3.11) and re-run this script"
|
||||
echo " Install a supported interpreter and re-run this script:"
|
||||
echo " pkg install tur-repo && pkg install python3.13"
|
||||
else
|
||||
echo -e "${RED}✗${NC} Python not found in Termux"
|
||||
echo " Run: pkg install python"
|
||||
|
||||
@@ -67,7 +67,8 @@ def _write_termux_command_stubs(bin_dir: Path) -> None:
|
||||
bin_dir / "uname",
|
||||
"#!/bin/sh\n[ \"${1:-}\" = '-s' ] && echo Linux || echo Linux\n",
|
||||
)
|
||||
_write_executable(bin_dir / "pkg", "#!/bin/sh\nexit 0\n")
|
||||
if not (bin_dir / "pkg").exists():
|
||||
_write_executable(bin_dir / "pkg", "#!/bin/sh\nexit 0\n")
|
||||
_write_executable(bin_dir / "git", "#!/bin/sh\necho 'git version 2.50.0'\n")
|
||||
_write_executable(bin_dir / "node", "#!/bin/sh\necho 'v22.12.0'\n")
|
||||
_write_executable(bin_dir / "npm", "#!/bin/sh\nexit 0\n")
|
||||
@@ -156,10 +157,39 @@ def test_install_stage_rejects_post_install_unsupported_default(tmp_path: Path)
|
||||
assert result.returncode == 1
|
||||
assert "Termux Python Python 3.14.6 is not supported" in result.stdout
|
||||
assert "Hermes requires Python >=3.11,<3.14" in result.stdout
|
||||
assert (
|
||||
"Install a compatible Termux Python (for example python3.11)" in result.stdout
|
||||
assert "pkg install tur-repo && pkg install python3.13" in result.stdout
|
||||
|
||||
|
||||
def test_install_stage_provisions_supported_python_from_tur(tmp_path: Path) -> None:
|
||||
"""When the default Termux python is too new, the installer falls back to
|
||||
the Termux User Repository (TUR) and picks up a supported interpreter that
|
||||
`pkg install python3.13` provides."""
|
||||
bin_dir = tmp_path / "bin"
|
||||
bin_dir.mkdir()
|
||||
_write_fake_python(bin_dir, "python", "3.14.6")
|
||||
# Shadow any host python3.11/3.12/3.13 so the candidate scan can't find a
|
||||
# supported interpreter before the TUR fallback runs.
|
||||
_write_unsupported_explicit_pythons(bin_dir)
|
||||
|
||||
# Stateful pkg stub: `pkg install -y python3.13` drops a supported fake
|
||||
# interpreter into PATH, mimicking a successful TUR package install.
|
||||
staged = tmp_path / "staged"
|
||||
staged.mkdir()
|
||||
_write_fake_python(staged, "python3.13", "3.13.7")
|
||||
_write_executable(
|
||||
bin_dir / "pkg",
|
||||
"#!/bin/sh\n"
|
||||
"for arg in \"$@\"; do\n"
|
||||
f" if [ \"$arg\" = 'python3.13' ]; then cp {staged}/python3.13 {bin_dir}/python3.13; fi\n"
|
||||
"done\n"
|
||||
"exit 0\n",
|
||||
)
|
||||
|
||||
result = _run_install_prerequisites(tmp_path)
|
||||
|
||||
assert result.returncode == 0, result.stdout
|
||||
assert "Python installed from TUR: Python 3.13.7" in result.stdout
|
||||
|
||||
|
||||
def test_setup_script_prefers_compatible_minor_over_unsupported_default(
|
||||
tmp_path: Path,
|
||||
|
||||
@@ -110,6 +110,22 @@ pkg install -y git python clang rust make pkg-config libffi openssl nodejs ripgr
|
||||
Why these packages?
|
||||
|
||||
- `python` — runtime + venv support
|
||||
|
||||
:::warning Supported Python range
|
||||
Hermes requires **Python >=3.11,<3.14**. Current Termux ships `python`
|
||||
3.14.x, which is outside that range — the installer detects this, and will
|
||||
automatically try the [Termux User Repository (TUR)](https://github.com/termux-user-repository/tur)
|
||||
for a supported interpreter. For a manual install, get one yourself:
|
||||
|
||||
```bash
|
||||
pkg install tur-repo
|
||||
pkg install python3.13
|
||||
```
|
||||
|
||||
Then use `python3.13` in place of `python` in the commands below
|
||||
(e.g. `python3.13 -m venv venv`).
|
||||
:::
|
||||
|
||||
- `git` — clone/update the repo
|
||||
- `clang`, `rust`, `make`, `pkg-config`, `libffi`, `openssl` — needed to build a few Python dependencies on Android
|
||||
- `nodejs` — optional Node runtime for experiments beyond the tested core path
|
||||
|
||||
Reference in New Issue
Block a user