From 5b0133c0ecedf71a23e5d9bf6fbefc91008e5101 Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 6 Jun 2025 21:15:52 +0200 Subject: [PATCH] Hint at `tool.uv.required-environments` (#13575) For the case where there was no matching wheel on sync, we previously added a note about which wheels are available vs. on which platform you are on. We extend this error message to link directly towards `tool.uv.required-environments`, which otherwise has a discovery problem. On Linux (Setting `tool.uv.required-environments` doesn't help here either, but it's a clear example): ``` [project] name = "debug" version = "0.1.0" requires-python = "==3.10.*" dependencies = ["tensorflow-macos>=2.13.1"] ``` ``` Resolved 41 packages in 24ms error: Distribution `tensorflow-macos==2.16.2 @ registry+https://pypi.org/simple` can't be installed because it doesn't have a source distribution or wheel for the current platform hint: You're on Linux (`manylinux_2_39_x86_64`), but there are no wheels for the current platform, consider configuring `tool.uv.required-environments`. hint: `tensorflow-macos` (v2.16.2) only has wheels for the following platform: `macosx_12_0_arm64`. ``` ![image](https://github.com/user-attachments/assets/b6b49461-10d6-4e1d-bc0a-5d35d98e33d0) --------- Co-authored-by: Zanie Blue --- crates/uv-resolver/src/lock/mod.rs | 41 +++++------ crates/uv/tests/it/sync.rs | 68 ++++++++++++++++++ ...heel_tag_test-0.1.0-py3-none-win_amd64.whl | Bin 0 -> 1367 bytes 3 files changed, 84 insertions(+), 25 deletions(-) create mode 100644 scripts/links/wheel_tag_test-0.1.0-py3-none-win_amd64.whl diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index fc79af00c..faacae736 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -5084,32 +5084,23 @@ impl std::fmt::Display for WheelTagHint { } else { format!("`{}`", best.cyan()) }; - if let Some(version) = version { - write!( - f, - "{}{} You're on {}, but `{}` ({}) only has wheels for the following platform{s}: {}", - "hint".bold().cyan(), - ":".bold(), - best, - package.cyan(), - format!("v{version}").cyan(), - tags.iter() - .map(|tag| format!("`{}`", tag.cyan())) - .join(", "), - ) + let package_ref = if let Some(version) = version { + format!("`{}` ({})", package.cyan(), format!("v{version}").cyan()) } else { - write!( - f, - "{}{} You're on {}, but `{}` only has wheels for the following platform{s}: {}", - "hint".bold().cyan(), - ":".bold(), - best, - package.cyan(), - tags.iter() - .map(|tag| format!("`{}`", tag.cyan())) - .join(", "), - ) - } + format!("`{}`", package.cyan()) + }; + writeln!( + f, + "{}{} You're on {}, but {} only has wheels for the following platform{s}: {}; consider adding your platform to `{}` to ensure uv resolves to a version with compatible wheels", + "hint".bold().cyan(), + ":".bold(), + best, + package_ref, + tags.iter() + .map(|tag| format!("`{}`", tag.cyan())) + .join(", "), + "tool.uv.required-environments".green() + ) } else { if let Some(version) = version { write!( diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 1cd6a1b88..c2026d51c 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -9608,3 +9608,71 @@ fn direct_url_dependency_metadata() -> Result<()> { Ok(()) } + +#[cfg(unix)] +#[test] +fn sync_required_environment_hint() -> Result<()> { + let context = TestContext::new("3.13"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "example" + version = "0.1.0" + requires-python = ">=3.13.2" + dependencies = ["wheel_tag_test"] + "#, + )?; + + // Populate the `--find-links` entries. + fs_err::create_dir_all(context.temp_dir.join("links"))?; + + for entry in fs_err::read_dir(context.workspace_root.join("scripts/links"))? { + let entry = entry?; + let path = entry.path(); + if path + .file_name() + .and_then(|file_name| file_name.to_str()) + .is_some_and(|file_name| file_name.starts_with("wheel_tag_test-")) + { + let dest = context + .temp_dir + .join("links") + .join(path.file_name().unwrap()); + fs_err::copy(&path, &dest)?; + } + } + + uv_snapshot!(context.filters(), context.lock() + .arg("--no-index") + .arg("--find-links") + .arg(context.temp_dir.join("links")), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + "); + + let mut filters = context.filters(); + filters.push((r"(macOS|Linux) \(`.*`\)", "[PLATFORM] (`[TAG]`)")); + + uv_snapshot!(filters, context.sync() + .arg("--no-index") + .arg("--find-links") + .arg(context.temp_dir.join("links")), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + error: Distribution `wheel-tag-test==0.1.0 @ registry+links` can't be installed because it doesn't have a source distribution or wheel for the current platform + + hint: You're on [PLATFORM] (`[TAG]`), but `wheel-tag-test` (v0.1.0) only has wheels for the following platform: `win_amd64`; consider adding your platform to `tool.uv.required-environments` to ensure uv resolves to a version with compatible wheels + "); + + Ok(()) +} diff --git a/scripts/links/wheel_tag_test-0.1.0-py3-none-win_amd64.whl b/scripts/links/wheel_tag_test-0.1.0-py3-none-win_amd64.whl new file mode 100644 index 0000000000000000000000000000000000000000..7a53b603bb9b998ba4305541f0bdf07d3d7713a0 GIT binary patch literal 1367 zcmWIWW@Zs#U|`??VyA#5MrLnqfGiM}0^;(F)YP2#lEn1*lGNf7{rLFIyv&mLc)fy3 zZ%^Og6TWB8T)q%;VQcV*)91anJ_=%JYFcz=j}WhF|CKp&YFf7}`V-UosprZSnY)vY zl-!+k<&lu9s;?eH0E(TyTcj1cfp#qcVs#8Vbq(|k^$heAWogTS%xznW`<_JzSw6A**{&nR>k+V9$=OG$ z@o&bK~_7>lMO) z{s;$R6~g`r_i%Of;Xd!-d-fu)x31Q?Gv_x48C)@bP~?BsTh~kHr2eL$6COIA=T4kF zFiuFn=O1k~do!35h-m_QVPw$kDhGySWEwH0? zJ$H`&ZT!S2 z?Ie-z&~d@$DSCPQVzG>nox9H#=1!^3&J*6h)%xn> z%PL>3coReGjvjZvY@=Joe(XYvUyN+N5Z}hxr+dUU>wewZ9BjUMe(e|Eiqd71`?uWH z-u2{y|B_sZ_I3tk9r13nM*nT+rJi_OcgTy$WtH80w<}xdY0Me^HEXs=?-f4p()H<; z(2Qf277AN_u?BcEGKnzb&ZEGv1cN1wAPRSmMK=dM-$6_P=0nC340CYiLUcpX6FL~;M9{gABpTq&$_CQL3WW24E?UG4 G;sF3MYSE+s literal 0 HcmV?d00001