Skip to content

Support multi-platform uv bootstrap assets#3073

Open
Pr030304 wants to merge 6 commits into
Netflix:masterfrom
Pr030304:feat-uv-bootstrap-multi-platform
Open

Support multi-platform uv bootstrap assets#3073
Pr030304 wants to merge 6 commits into
Netflix:masterfrom
Pr030304:feat-uv-bootstrap-multi-platform

Conversation

@Pr030304
Copy link
Copy Markdown

PR Type

  • Bug fix
  • New feature
  • Core Runtime change (higher bar -- see CONTRIBUTING.md)
  • Docs / tooling
  • Refactoring

Summary

Add multi-platform support to the uv bootstrap path by selecting the correct release asset for the current OS and architecture instead of hardcoding the Linux x86_64 tarball. This also makes the generated uv sync command shell-portable by removing the set -e; prefix.

Issue

Fixes #2642

Reproduction

Runtime: local

Commands to run:

python -m pytest test/unit/test_uv_bootstrap.py -v

Where evidence shows up: test output in the local console

Before (error / log snippet)
The uv bootstrap path hardcodes:
https://github.com/astral-sh/uv/releases/download/0.6.11/uv-x86_64-unknown-linux-gnu.tar.gz

That means bootstrap assumes:

  • Linux
  • x86_64
  • tar.gz archive layout
    This breaks portability for macOS and Windows environments and makes the bootstrap logic incompatible with non-Linux uv release assets.

The generated sync command also embeds:

set -e;

which assumes a POSIX shell command layout instead of generating a portable command chain.

After (evidence that fix works)
test/unit/test_uv_bootstrap.py::test_get_uv_download_info_linux_x86_64 PASSED
test/unit/test_uv_bootstrap.py::test_get_uv_download_info_darwin_arm64 PASSED
test/unit/test_uv_bootstrap.py::test_get_uv_download_info_windows_amd64 PASSED
test/unit/test_uv_bootstrap.py::test_get_uv_download_info_raises_for_unsupported_platform PASSED
test/unit/test_uv_bootstrap.py::test_build_uv_sync_cmd_uses_portable_command_chain PASSED

Root Cause

metaflow/plugins/uv/bootstrap.py hardcodes a single uv release URL:

UV_URL = "https://github.com/astral-sh/uv/releases/download/0.6.11/uv-x86_64-unknown-linux-gnu.tar.gz"

This bakes Linux x86_64 assumptions directly into the bootstrap path.

There are two separate issues caused by that:

  1. The bootstrap logic cannot choose the correct uv asset for macOS, Windows, or non-x86_64 systems.
  2. The extraction logic assumes a tar.gz archive containing a uv binary, which does not match Windows release assets.
    Additionally, the generated sync command uses a shell preamble with set -e;, which is unnecessarily tied to POSIX shell syntax instead of building a portable command chain.

Why This Fix Is Correct

This fix restores the intended invariant that uv bootstrap should be determined by the current platform rather than by a hardcoded Linux asset.

The implementation is intentionally scoped:

  • map (system, machine) to the correct uv release asset
  • normalize common architecture aliases such as AMD64 -> x86_64 and arm64 -> aarch64
  • support both tarball and zip release formats
  • keep the existing bootstrap structure otherwise unchanged
  • build the uv sync command as a normal command chain instead of embedding set -e;
    This keeps the change focused on platform-aware asset selection and command generation without changing the rest of the uv environment workflow.

Failure Modes Considered

  1. Unsupported platform / architecture combinations
    The new helper raises an explicit error for unsupported (system, machine) pairs instead of silently downloading the wrong asset.

  2. Archive format mismatch
    Windows uv releases are distributed as zip files, while Linux/macOS use tarballs. The bootstrap now handles both formats explicitly and validates that the expected executable is present in the archive.

Tests

  • Unit tests added/updated
  • Reproduction script provided (required for Core Runtime)
  • CI passes
  • If tests are impractical: explain why below and provide manual evidence above

Added test/unit/test_uv_bootstrap.py covering:

  • Linux x86_64 asset selection
  • macOS ARM64 asset selection
  • Windows AMD64 asset selection
  • unsupported platform failure
  • portable uv sync command generation

Locally ran:

python -m pytest test/unit/test_uv_bootstrap.py -v

Non-Goals

This PR does not:

  • change how uv environments are resolved beyond platform-aware bootstrap
  • refactor the full uv bootstrap workflow
  • add support for every uv target published upstream
  • change the pinned uv version beyond making it configurable through the existing bootstrap logic

AI Tool Usage

  • No AI tools were used in this contribution
  • AI tools were used (describe below)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 31, 2026

Greptile Summary

This PR replaces the hardcoded Linux x86_64 uv download URL with a platform-aware asset-selection function (get_uv_download_info), extracts the sync command into a portable helper (build_uv_sync_cmd), and bundles three additional clean-ups: an off-by-one / StopIteration fix in card_server.py, consolidation of the duplicate KubernetesException class, and a pip bootstrapping guard in MetaflowEnvironment._get_install_dependencies_cmd. All changes are covered by new unit tests.

Key changes:

  • bootstrap.py: get_uv_download_info() maps (system, machine) → correct GitHub release asset for Linux, macOS, and Windows (tar.gz / zip); build_uv_sync_cmd() builds a portable &&-chained command, removing the set -e; preamble. Both functions are module-level so they are importable and testable independently.
  • metaflow_environment.py: Adds a shell guard that runs ensurepip if pip is absent before invoking pip install; contains a cosmetic redundancy (line 196 duplicates line 195's pip --version check) that should be removed.
  • card_server.py: Moves curr_idx += 1 after the max_cards guard (fixes off-by-one) and replaces the deprecated raise StopIteration with return.
  • kubernetes.py: Removes locally-duplicated KubernetesException and re-exports it from kube_utils.

Confidence Score: 5/5

Safe to merge; the only remaining finding is a harmless redundant shell expression that does not affect runtime behaviour.

All previously raised P1 concerns (subshell exit 1, empty-dependencies invalid command) have been addressed. The single remaining comment is a copy-paste duplicate of a pip --version check that is functionally inert — the command chain still terminates with the correct error if pip cannot be bootstrapped. No logic bugs, data integrity issues, or security problems were found.

metaflow/metaflow_environment.py line 196 — redundant pip --version check worth removing for clarity.

Important Files Changed

Filename Overview
metaflow/plugins/uv/bootstrap.py Adds platform-aware uv asset selection via get_uv_download_info(), extracts build_uv_sync_cmd() as a portable command builder (no set -e), and handles both tar.gz and zip archive formats; logic is correct and well-tested.
metaflow/metaflow_environment.py Adds pip bootstrapping guard before running pip install, using brace groups for correct exit semantics; contains a redundant duplicate pip --version check on line 196 that should be removed.
metaflow/plugins/cards/card_server.py Fixes an off-by-one bug (increment after check, not before) and replaces the deprecated raise StopIteration inside a generator with return; logic is correct and the new tests verify both boundary cases.
metaflow/plugins/kubernetes/kubernetes.py Removes the locally-duplicated KubernetesException class and imports it from kube_utils instead; clean refactor with a test confirming both import paths resolve to the same class object.
test/unit/test_uv_bootstrap.py New unit tests covering Linux x86_64, macOS arm64, Windows AMD64 asset selection, unsupported-platform error, and portable sync-command generation; all cases look correct.
test/unit/test_card_server.py New unit tests for cards_for_run that verify the max_cards boundary (exactly 20 cards returned) and the below-limit case; correctly exercises the off-by-one fix.
test/unit/test_metaflow_environment.py New integration-style unit tests using a fake Python shim to verify the pip bootstrapping shell commands end-to-end; covers the install-on-missing path and the METAFLOW_SKIP_INSTALL_DEPENDENCIES skip path.
test/unit/test_kubernetes.py Adds a test asserting that KubernetesException imported from kubernetes.py and kube_utils are the same class object, confirming the refactor preserves the public API.

Reviews (3): Last reviewed commit: "Update metaflow/metaflow_environment.py" | Re-trigger Greptile

Comment thread metaflow/metaflow_environment.py Outdated
Comment thread metaflow/plugins/uv/bootstrap.py Outdated
Pr030304 and others added 2 commits March 31, 2026 14:49
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv support for multiple platforms/architecture

1 participant