Merge pull request #26 from s-diaco/cursor/fix-linux-gi-venv-c182
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Keep apt gi by pinning Linux setup to system Python
This commit is contained in:
@@ -5,6 +5,8 @@ set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
SYS_PY=/usr/bin/python3
|
||||
|
||||
if ! command -v uv >/dev/null 2>&1; then
|
||||
echo "uv not found on PATH. Install uv first: https://docs.astral.sh/uv/" >&2
|
||||
exit 1
|
||||
@@ -16,6 +18,11 @@ if ! command -v apt-get >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -x "$SYS_PY" ]]; then
|
||||
echo "System Python not found at $SYS_PY" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
packages=(python3-gi gir1.2-gtk-3.0)
|
||||
if apt-cache show gir1.2-webkit2-4.1 >/dev/null 2>&1; then
|
||||
packages+=(gir1.2-webkit2-4.1)
|
||||
@@ -41,6 +48,23 @@ else
|
||||
echo "GTK/WebKitGTK requirements already installed."
|
||||
fi
|
||||
|
||||
if ! "$SYS_PY" -c 'import gi' >/dev/null 2>&1; then
|
||||
echo "System $SYS_PY cannot import gi. Install python3-gi." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
enable_system_site_packages() {
|
||||
local cfg=.venv/pyvenv.cfg
|
||||
if [[ ! -f "$cfg" ]]; then
|
||||
return 1
|
||||
fi
|
||||
if grep -q '^include-system-site-packages' "$cfg"; then
|
||||
sed -i 's/^include-system-site-packages = .*/include-system-site-packages = true/' "$cfg"
|
||||
else
|
||||
printf '\ninclude-system-site-packages = true\n' >> "$cfg"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ ! -x .venv/bin/python ]] || ! .venv/bin/python -c 'import gi' >/dev/null 2>&1; then
|
||||
echo "Creating venv with the system Python and system site packages..."
|
||||
rm -rf .venv
|
||||
@@ -48,7 +72,22 @@ if [[ ! -x .venv/bin/python ]] || ! .venv/bin/python -c 'import gi' >/dev/null 2
|
||||
fi
|
||||
|
||||
echo "Syncing dependencies..."
|
||||
uv sync --active
|
||||
# Pin the same interpreter so uv does not honor .python-version (3.12) and
|
||||
# recreate a managed venv without apt gi (python3-gi).
|
||||
uv sync --python /usr/bin/python3 --no-managed-python
|
||||
|
||||
if ! .venv/bin/python -c 'import gi' >/dev/null 2>&1; then
|
||||
echo "Restoring system site packages on .venv so apt gi is importable..."
|
||||
enable_system_site_packages
|
||||
fi
|
||||
|
||||
venv_ver="$(.venv/bin/python -c 'import sys; print("%d.%d" % sys.version_info[:2])')"
|
||||
sys_ver="$("$SYS_PY" -c 'import sys; print("%d.%d" % sys.version_info[:2])')"
|
||||
if [[ "$venv_ver" != "$sys_ver" ]]; then
|
||||
echo "venv Python $venv_ver does not match system Python $sys_ver at $SYS_PY." >&2
|
||||
echo "uv likely honored .python-version instead of the system interpreter." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Verifying GTK and WebKit2 bindings..."
|
||||
.venv/bin/python -c '
|
||||
|
||||
19
tests/test_setup_linux.py
Normal file
19
tests/test_setup_linux.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_setup_linux_pins_system_python_for_uv_sync():
|
||||
script = Path("desktop/setup_linux.sh").read_text(encoding="utf-8")
|
||||
|
||||
assert "uv venv --python /usr/bin/python3 --no-managed-python --system-site-packages" in script
|
||||
|
||||
sync_lines = [
|
||||
line.strip()
|
||||
for line in script.splitlines()
|
||||
if line.strip().startswith("uv sync")
|
||||
]
|
||||
assert sync_lines == [
|
||||
"uv sync --python /usr/bin/python3 --no-managed-python"
|
||||
]
|
||||
assert "--python-preference" not in script
|
||||
assert "uv sync --active" not in script
|
||||
assert "include-system-site-packages = true" in script
|
||||
Reference in New Issue
Block a user