Skip to content

Preserve a registry wheel for pylock.toml when marker filtering removes every distribution - #23320

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/retain-wheel-for-lock-validation
Draft

charliermarsh wants to merge 1 commit into
mainfrom
charlie/retain-wheel-for-lock-validation

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

On macOS, pip rejects this universal lockfile before it can install Jupyter Core.

echo "jupyter-core==5.8.1; os_name != 'nt'" | uv pip compile --universal --python 3.12 -o pylock.toml -
python -m pip install --dry-run -r pylock.toml

Jupyter requests pywin32 on Windows outside PyPy. The resolver admits sys_platform == 'win32' together with the caller's os_name != 'nt', so it includes pywin32. The wheel filter requires os_name == 'nt' for Windows wheels, which removes every file. With no sdist to record, we write just the name, version and marker. pip validates each package's source before checking its marker, so the empty entry prevents installation even on macOS. Jupyter dependency

When the marker removes every wheel and there is no sdist, uv pip compile now keeps one wheel in the pylock entry. The wheel must come from the selected index, pass the existing tag checks for the Python range and target, and satisfy the resolver’s yanking policy. The selection favors a wheel that meets the index's hash requirements, then an unyanked file, then a file with an advertised hash. The filename and URL break ties. Pip can validate the source and skip pywin32 on macOS. If the marker applies on a target where the wheel is incompatible, installation still fails for that package. Installation rules

For frozen export, uv lock records that candidate in an optional fallback-wheel field when the package would otherwise have no distribution and the index permits recording the file. Only uv export --format pylock.toml uses it as a package source. Keeping the field separate from wheels keeps the extra digest out of native build verification and requirements exports. Older lockfiles need a fresh resolution to acquire the field. If every candidate fails the index’s hash requirements, the native lock omits the field and the frozen export can still lack a source. If the index omits hashes, producing the pylock file may require downloading that wheel to compute its hash.

Comment thread crates/uv-lock/src/lock/mod.rs Resolved
Comment thread crates/uv-lock/src/lock/mod.rs Resolved
@charliermarsh
charliermarsh removed this pull request from stack #23321 November 20, 2026 18:01
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 23c5640 to 9fd9819 Compare November 20, 2026 18:07
@charliermarsh charliermarsh changed the title Keep wheels needed to validate lockfiles when platform markers exclude them Keep pylock.toml readable when platform filtering removes the last wheel Nov 20, 2026
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 9fd9819 to bcd3d5e Compare November 20, 2026 21:14
@charliermarsh charliermarsh changed the title Keep pylock.toml readable when platform filtering removes the last wheel Keep a wheel when platform filtering would leave a compiled pylock.toml entry empty Nov 20, 2026
Comment thread crates/uv-lock/src/lock/mod.rs Resolved
Comment thread crates/uv-lock/src/lock/mod.rs Resolved
Comment thread crates/uv/tests/it/proxy_index.rs Resolved
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from bcd3d5e to 17e1dc8 Compare November 20, 2026 21:31
Comment thread crates/uv-lock/src/lock/mod.rs Resolved
Comment thread crates/uv-lock/src/lock/mod.rs Resolved
Comment thread crates/uv/tests/it/proxy_index.rs Resolved
@charliermarsh
charliermarsh removed this pull request from stack #23333 November 20, 2026 21:42
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 17e1dc8 to 320474c Compare November 20, 2026 22:03
Comment thread crates/uv/tests/it/proxy_index.rs Resolved
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 320474c to 6003c22 Compare November 21, 2026 01:30
@charliermarsh charliermarsh changed the title Keep a wheel when platform filtering would leave a compiled pylock.toml entry empty Exclude environments with missing distributions from pylock.toml Nov 21, 2026
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 6003c22 to 4c3c4c6 Compare November 21, 2026 02:01
Comment thread crates/uv-pep508/src/marker/algebra.rs Resolved
Comment thread crates/uv/tests/project/export.rs Resolved
@charliermarsh
charliermarsh force-pushed the charlie/retain-wheel-for-lock-validation branch from 4c3c4c6 to 2ec7ded Compare November 21, 2026 02:20
@charliermarsh charliermarsh changed the title Exclude environments with missing distributions from pylock.toml Preserve a registry wheel for pylock.toml when marker filtering removes every distribution Nov 21, 2026
.peekable();

let fallback = if sdist.is_none() && matching.peek().is_none() {
select_fallback_wheel(node, requires_python, tags, index_locations)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Enforce the index hash algorithm for fallback wheels

If an index requires SHA-256 but its only eligible fallback advertises just MD5, select_fallback_wheel still returns it and uv pip compile writes the MD5 into pylock.toml. If a non-proxied index advertises no hash, compile downloads the wheel and hashes whatever bytes the artifact host serves. Both paths bypass the requirement for an index-advertised SHA-256. The fallback can still be installed on a 32-bit Linux interpreter that reports platform_machine == 'x86_64' while accepting i686 wheels.

Suggested change
select_fallback_wheel(node, requires_python, tags, index_locations)
let fallback = select_fallback_wheel(node, requires_python, tags, index_locations);
if let Some(wheel) = fallback {
let _ = crate::lock::select_registry_hash(
&wheel.file.hashes,
&wheel.index,
index_locations,
wheel.file.filename.as_ref(),
)?;
}
fallback

let wheels = package
.wheels
.iter()
.chain(fallback)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Check the locked fallback size before recording its digest

A non-proxied index can supply a wheel size without a hash. When uv export --frozen --format pylock.toml includes that fallback, generate_missing_hashes passes only its URL to RegistryClient::hash_file. If the artifact host serves different-length bytes after locking, export succeeds and records their SHA-256 alongside the original size. uv will reject that pair if it later selects the wheel. Pass the locked size into hash completion and reject a byte-count mismatch before writing the digest.

Comment on lines +316 to +318
if let Some(wheel) = &package.fallback_wheel {
writer.key_start("fallback-wheel")?;
write_wheel_inline(writer, wheel)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve the fallback wheel’s advertised filename in uv.lock

A JSON index can advertise demo-1.0-py3-none-win32.whl at /downloads/42. write_wheel_inline records only the URL, and Wheel::try_from(WheelWire) then tries to parse 42 as a wheel filename. uv lock can therefore write a lockfile that uv export --frozen cannot read. The same encoding limitation exists for ordinary wheels at the merge base, but marker filtering previously omitted this wheel and left the native lock readable. Record and honor the advertised filename when it cannot be recovered from the fallback URL; the broader ordinary-wheel fix can follow.

Comment on lines +10746 to +10748
!can_lock_fallback(wheel, index_locations),
wheel.file.yanked.as_deref().is_some_and(Yanked::is_yanked),
wheel.file.hashes.is_empty(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Rank fallback wheels the pylock writer can serialize first

Consider a pinned package on a proxied index configured for SHA-512, with two marker-incompatible wheels: an unyanked wheel without a hash and a permitted yanked wheel with SHA-256. Both fail can_lock_fallback, so yank status selects the hashless wheel and validate_proxy_artifact aborts compilation. The pylock writer accepts the SHA-256 wheel; it is the native writer that requires the configured algorithm. The merge base omitted both wheels. Prefer candidates that pass pylock’s mandatory proxy-hash check before applying the yank tie-break, while retaining the configured-algorithm filter for uv.lock.

Comment on lines 7792 to +7793
#[serde(default)]
fallback_wheel: Option<Box<Wheel>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Track the fallback-wheel field in the lockfile revision

docs/concepts/resolution.md names adding a distribution field as an example of a backwards-compatible revision change. Both old and new writers currently emit revision 5, so when fallback-wheel is absent, a reader cannot distinguish a writer that never considered a fallback from one that found no recordable candidate. Increment REVISION and document the field in the revision history; this need not force old lockfiles to re-resolve.

name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["demo==1.0; sys_platform == 'freebsd'"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Exercise rejection of a yanked fallback, not just its ranking

The exact pin permits the yanked build, so the snapshots still pass if rejected_yank is always false: the unyanked hashed build wins on ranking alone. A focused compile case with an unpinned dependency, a hashless unyanked proxy wheel, and a yanked wheel as the only hashed candidate would distinguish the two rules. It should report the missing proxy hash rather than export the rejected wheel.

Comment on lines +1506 to +1510
let requirements = context.export().arg("--frozen").output()?;
assert!(requirements.status.success());
let requirements = String::from_utf8(requirements.stdout)?;
assert!(requirements.contains("demo==1.0"));
assert!(!requirements.contains(WHEEL_HASH));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Snapshot the requirements export directly

These substring checks pass if the export drops the FreeBSD marker or emits a different digest, and a failed status assertion does not show the command’s stderr. Use uv_snapshot! with export --frozen --no-header, as in the neighboring export tests. The expected requirement line shows both the marker and the absence of a hash without manually parsing stdout.

This branch was previously deployed

1 inactive (outdated) deployment
automations — 9fd9819d Deployed Nov 20, 2026 by charliermarsh via review | security / security review #54225
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.

1 participant