Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion lib/runtime.func
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
Loading