Keep apt gi by pinning Linux setup to system Python.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
uv sync --active was honoring .python-version (3.12) and replacing the system-site-packages venv, so python3-gi from Ubuntu's interpreter was no longer importable. Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
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 --python-preference only-system
|
||||
|
||||
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 '
|
||||
|
||||
Reference in New Issue
Block a user