Skip to content

Commit 90db5cc

Browse files
committed
setup_uv: honour a project's required-version pin
uv refuses to run when the project pins a required-version it does not match, in either direction, so RomM's ==0.12.13 fails against both the 0.10.3 a container was built with and the 0.12.17 an update installs. An optional project directory makes setup_uv read that pin. Without the argument nothing changes, so all 115 existing call sites keep working. Only the exact == form is read; a range falls through to latest.
1 parent cae1921 commit 90db5cc

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎lib/API.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ _setup_nvidia_gpu
4242
_setup_rocm
4343
_tools_cleanup_temp_dirs
4444
_tools_register_temp_cleanup
45+
_uv_required_version
4546
cache_installed_version
4647
check_for_codeberg_release
4748
check_for_gh_branch

‎lib/runtime.func‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,26 @@ setup_rust() {
24732473
# - Optionally installs a specific Python version via uv
24742474
# ------------------------------------------------------------------------------
24752475

2476+
# uv refuses to run when a project pins a required-version it does not match,
2477+
# in either direction. Only the exact form is read; a range falls through to
2478+
# whatever the caller would have installed anyway.
2479+
_uv_required_version() {
2480+
local dir="${1:?dir}" f v
2481+
for f in "$dir/pyproject.toml" "$dir/uv.toml"; do
2482+
[[ -f "$f" ]] || continue
2483+
v="$(grep -m1 -E '^[[:space:]]*required-version[[:space:]]*=' "$f" 2>/dev/null |
2484+
sed -E 's/.*=[[:space:]]*"[[:space:]]*==[[:space:]]*([0-9][0-9A-Za-z.+-]*)"[[:space:]]*$/\1/')"
2485+
if [[ "$v" =~ ^[0-9] ]]; then
2486+
echo "$v"
2487+
return 0
2488+
fi
2489+
done
2490+
return 1
2491+
}
2492+
2493+
# $1 - optional project directory; its uv pin wins over the latest release
24762494
setup_uv() {
2495+
local PROJECT_DIR="${1:-}"
24772496
local UV_BIN="/usr/local/bin/uv"
24782497
local UVX_BIN="/usr/local/bin/uvx"
24792498
local TMP_DIR=$(mktemp -d)
@@ -2510,8 +2529,11 @@ setup_uv() {
25102529

25112530
ensure_dependencies jq
25122531

2513-
# Fetch target version (pinned via UV_VERSION or latest release)
2532+
# Fetch target version (UV_VERSION, then the project's own pin, then latest)
25142533
local TARGET_VERSION="${UV_VERSION:-}"
2534+
if [[ -z "$TARGET_VERSION" && -n "$PROJECT_DIR" ]]; then
2535+
TARGET_VERSION="$(_uv_required_version "$PROJECT_DIR")" || TARGET_VERSION=""
2536+
fi
25152537
if [[ -z "$TARGET_VERSION" ]]; then
25162538
TARGET_VERSION=$(get_latest_github_release "astral-sh/uv") || {
25172539
msg_error "Could not fetch latest uv version from GitHub API"

0 commit comments

Comments
 (0)