Repository navigation
Add prototype implementation of wheel variant specification - #12203
charliermarsh wants to merge 35 commits into
Conversation
6ca5626 to
f598b60
Compare
|
The But then it seems to succeed. |
|
Ah sorry. I’ll update the instructions. You can either remove that section from the pyproject.toml, then run the build script, then re-add it. Or run cargo build, then point the build script to ./target/debug/uv instead of your global uv. |
|
And the |
I had a feeling about that! |
|
You can run uv venv prior to the cargo run command to create a virtual environment in the current working directory. cargo run will then install into that virtual environment by default. |
|
[[tool.uv.variant]]
backend = "provider_fictional_hw.plugin:build"
requires = ["provider_fictional_hw"]For this configuration I'm curious if this would be end-user facing or would this be package maintainer facing? From my POV I feel like this would be best served at the package maintainer side where a potential PyTorch packaging config might look like: [[tool.uv.variant]]
backend = "torch.build.variants:detect_variants"
requires = ["cuda_variants", "rocm_variants", "xpu_variants", "your_fav_hardware_variants"]fwiw I don't know if requiring people to install variant plugins themselves is necessarily going to be a way to adopt this heavily since this should be something that reduces the friction towards someone installing the correct package for their machine instead of them having to remember which variant plugins they're installing vs. not. |
|
I was thinking it would be declared by the package maintainer, but possibly overridable by the end user (so, like, if they don't care about |
f598b60 to
189dd02
Compare
|
(Applied your changes, thanks @warsawnv.) |
bd7d6d2 to
9146f46
Compare
18dfd1e to
5ac01b8
Compare
5ae7861 to
f168655
Compare
Record the location and SHA-256 of the exact sidecar used to resolve a package, independently of the hashes of its wheels.
Let the locked graph choose an artifact independently of walking the dependencies reachable from it.
… time Apply the upload-time cutoff before preferring an ordinary wheel as a metadata source.
Provider authorization and package resolution have distinct trust boundaries. Credential-bearing provider URLs must stay out of generated command headers and argument errors.
| vec![Index::from_index_url(index.clone())], | ||
| vec![], | ||
| vec![], | ||
| false, |
There was a problem hiding this comment.
[P2] Honor --no-index when resolving external providers
The provider resolver hard-codes no_index to false. With the wheel-variants preview and an external provider configured in the environment, a wheel from a local --find-links directory can trigger a registry download during uv pip install --no-index. uv then executes the downloaded provider under the user’s account. Inherit the invocation’s index policy when constructing the provider resolver.
| false, | |
| dispatch.index_locations.no_index(), |
| flat_index: &flat_index, | ||
| base_hasher: &hasher, | ||
| build_hash_checking: HashCheckingMode::Verify, | ||
| exclude_newer: ExcludeNewer::default(), |
There was a problem hiding this comment.
[P2] Apply the dependency cooldown to provider wheels
Resetting exclude_newer lets the provider resolver install a provider or transitive dependency uploaded after the operator’s --exclude-newer cutoff. When an authorized provider has an unpinned dependency, a new release on the authorized index can run under the user’s account during variant detection, before the configured cooldown expires.
| exclude_newer: ExcludeNewer::default(), | |
| exclude_newer: ExcludeNewer::clone(&dispatch.exclude_newer), |
| BuildIsolation::SharedPackage(venv, packages) | ||
| } | ||
| }; | ||
| let variant_client = has_variants.then(build_client).transpose()?; |
There was a problem hiding this comment.
[P2] Suppress host provider execution during cross-platform sync
uv sync --frozen --python-platform uses the requested platform for wheel tags but leaves VariantPolicy::explicit_platform false. With the wheel-variants preview and an external provider enabled, a reachable sidecar can trigger Python code on the build host and use its hardware properties to choose the wheel and dependencies for the target. Set the flag on the policy shared by selection and installation, as the pip commands do.
| let variant_client = has_variants.then(build_client).transpose()?; | |
| let variant_policy = &variant_policy | |
| .clone() | |
| .with_explicit_platform(python_platform.is_some()); | |
| let variant_client = has_variants.then(build_client).transpose()?; |
| let mut table = InlineTable::new(); | ||
| match &self.url { | ||
| VariantsJsonSource::Url { url } => { | ||
| table.insert("url", Value::from(url.as_ref())); |
There was a problem hiding this comment.
[P2] Keep sidecar download credentials out of uv.lock
VariantsJsonEntry retains the advertised sidecar URL, and this write copies its raw string into uv.lock. If a private index returns a sidecar link with HTTP credentials or a signed query, anyone who receives the lockfile can reuse that authorization while it remains valid, even when the recorded index and wheel URLs are clean. Persist a credential-free locator and obtain download authorization at fetch time, using the locked SHA-256 to verify the sidecar.
| .iter() | ||
| .enumerate() | ||
| .skip(first_candidate) | ||
| .filter(|(_, wheel)| wheel.index == sidecar.index) |
There was a problem hiding this comment.
[P2] Exclude already-yanked variants from new locks
On an index that yanks individual files, a new unpinned resolution can select a release through its ordinary wheel while retaining a variant already marked IncompatibleWheel::Yanked. The lock drops that status, and frozen sync ranks the retained variant by tags and sidecar properties. It can therefore install a wheel the index had already withdrawn for a security issue. Exclude rejected variants before collecting their dependencies and writing the lock, while the resolver still knows whether an explicit pin permits the yank.
| let ordinary = registry.best_wheel().filename.variant().is_none(); | ||
| return Ok(ordinary.then_some((node, None))); | ||
| }; | ||
| registry.best_wheel_index = index; |
There was a problem hiding this comment.
[P3] Enforce the locked size of the selected registry variant
The selected registry wheel retains size_is_authoritative = false, so the downloader treats its uv.lock size as a progress hint. If a registry entry records a size without a digest, uv sync --frozen can install a different-length replacement from the artifact host. A recorded digest still protects the wheel contents when present.
| registry.best_wheel_index = index; | |
| registry.best_wheel_index = index; | |
| registry.wheels[index].size_is_authoritative = true; |
(Branch taken over by @konstin)
See #22043 for a status tracker
This branch contains the prototype implementation of the wheel variants proposal. It builds directly on #22758, the highest branch in the wheel variant tracker. The diff shows the implementation still to review after that stack: 35 commits, about 8,400 added and 2,300 removed lines across 120 files. The work still missing from this branch is listed below. Please keep #22043 open as pieces land.
It supports
uv pip install,uv lockanduv syncfor the covered cases. Included are:variants.json, and carrying the metadata that apylock.tomlconsumer needs.Naturally, it is not ready for any serious usage yet. Expect that things break, please report problems.
release The installers below are for the historical WheelNext prototype releases. The commands under latest use this branch’s current interface.
Unix:
curl -LsSf https://astral.sh/uv/install.sh | INSTALLER_DOWNLOAD_URL=https://wheelnext.astral.sh/v0.0.2 shWindows:
On this branch, enable wheel variants with
--preview-features wheel-variantsorUV_PREVIEW_FEATURES=wheel-variants. This opt-in also applies to direct variant wheels and existing variant lockfiles.latest Clone the repo and check out
charlie/wheel-variant. This self-contained example creates wheels with different dependencies, writes one universal lock, then installs the preferred wheel and its dependency from that lock:cargo test -p uv --test pip_install --features test-python lock_variant_wheel_specific_dependenciesTo try an index serving the current metadata format, set
VARIANT_INDEXto its simple-index URL andVARIANT_PACKAGEto a package it serves. As in the original prototype,uv venvcreates a local environment for the install:If you don’t have Rust installed, there’s a bootstrapping process from current uv, though it’s slow:
To describe a target without querying providers, pass a JSON file with
--variant-targetorUV_VARIANT_TARGET. Compatible values are ordered from most to least preferred. This example describes an x86-64 v3 target;{}describes a target with no variant properties. This is a preview input format, separate from the package’svariants.json.{ "x86_64": [["level", ["v3", "v2", "v1"]]] }PEP 825 updates
PEP 825 is provisionally accepted. The provider interface follows the PEP 850 draft. Filename and metadata parsing, basic selection and ordering, static providers, and the NVIDIA and direct-wheel work are already in
mainor the stack below this PR.uv.lock, and check that digest when reading the sidecar again. A wheel hash authenticates the wheel, not a separate index response. Index metadatavariant_labelandvariant_propertiesfor the wheel that declared a dependency. Universal resolution retains alternative wheels and makes differing dependencies conditional. Only labels declared by the verified sidecar contribute variant dependencies; an unlisted wheel cannot displace an ordinary wheel or source archive supplying baseline metadata. Variant markers--variant-provider namespace=package@module:objectand a trusted--variant-provider-index; a wheel, project, or lockfile cannot grant that permission. Generated requirements and pylock headers omit the provider index, and an invalid provider index is reported without printing its credentials. External providers run as the current user. An explicit cross-platform target doesn’t inherit detected host properties. Provider executionThe local scenarios also cover namespace priority, fallback, and dependency markers from Packse #292.
Work still outstanding
pylock.tomlcan carry variant metadata, but its package and environment markers cannot express every such condition either. The affected exports fail explicitly. Pylock integrationabi_dependencyremains separate, lower-priority work in Wheel variant preview implementation tracker #22043.Review order
The commits build on one another, with tests beside the behavior they exercise. The median commit adds 256 lines. The first 23 commits extend the MVP, followed by the correctness and security changes needed to ship it. The shared wheel-cache changes, authenticated metadata reader, and locked selection are separate commits.
uv.lock, select a locked wheel before following its dependencies, sync across targets, and carry per-wheel dependencies through a universal lock andpylock.tomlwhere the format can represent them.--exclude-newer, skip discovery for ineligible wheels, resolve conflict-dependent reachability, and reject exports that would change the package set.