diff --git a/lib/API.txt b/lib/API.txt index d24317e..7aa63f9 100644 --- a/lib/API.txt +++ b/lib/API.txt @@ -42,6 +42,7 @@ _setup_nvidia_gpu _setup_rocm _tools_cleanup_temp_dirs _tools_register_temp_cleanup +_uv_required_version cache_installed_version check_for_codeberg_release check_for_gh_branch diff --git a/lib/runtime.func b/lib/runtime.func index 649ceb0..92b73ac 100644 --- a/lib/runtime.func +++ b/lib/runtime.func @@ -2473,7 +2473,27 @@ setup_rust() { # - Optionally installs a specific Python version via uv # ------------------------------------------------------------------------------ +# uv refuses to run when a project pins a required-version it does not match, +# in either direction. Only the exact form is read; a range falls through to +# whatever the caller would have installed anyway. +_uv_required_version() { + local dir="${1:?dir}" f v + for f in "$dir/pyproject.toml" "$dir/uv.toml"; do + [[ -f "$f" ]] || continue + v="$(grep -m1 -E '^[[:space:]]*required-version[[:space:]]*=' "$f" 2>/dev/null | + sed -E 's/.*=[[:space:]]*"[[:space:]]*==[[:space:]]*([0-9][0-9A-Za-z.+-]*)"[[:space:]]*$/\1/')" + if [[ "$v" =~ ^[0-9] ]]; then + echo "$v" + return 0 + fi + done + return 1 +} + +# UV_PROJECT_DIR - optional project directory; its uv pin wins over the latest +# release. Set as a prefix, like PYTHON_VERSION and UV_VERSION. setup_uv() { + local PROJECT_DIR="${UV_PROJECT_DIR:-}" local UV_BIN="/usr/local/bin/uv" local UVX_BIN="/usr/local/bin/uvx" local TMP_DIR=$(mktemp -d) @@ -2510,8 +2530,11 @@ setup_uv() { ensure_dependencies jq - # Fetch target version (pinned via UV_VERSION or latest release) + # Fetch target version (UV_VERSION, then the project's own pin, then latest) local TARGET_VERSION="${UV_VERSION:-}" + if [[ -z "$TARGET_VERSION" && -n "$PROJECT_DIR" ]]; then + TARGET_VERSION="$(_uv_required_version "$PROJECT_DIR")" || TARGET_VERSION="" + fi if [[ -z "$TARGET_VERSION" ]]; then TARGET_VERSION=$(get_latest_github_release "astral-sh/uv") || { msg_error "Could not fetch latest uv version from GitHub API"