Apply build constraints when resolving --with dependencies (#14340)

## Summary

We were applying these at install time, but not resolve time.
This commit is contained in:
Charlie Marsh 2025-06-27 21:39:35 -04:00 committed by GitHub
parent b6b7409d13
commit 731689e503
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 7 additions and 6 deletions

View file

@ -51,6 +51,7 @@ impl CachedEnvironment {
resolve_environment(
spec,
&interpreter,
build_constraints.clone(),
&settings.resolver,
network_settings,
state,

View file

@ -1746,6 +1746,7 @@ impl<'lock> EnvironmentSpecification<'lock> {
pub(crate) async fn resolve_environment(
spec: EnvironmentSpecification<'_>,
interpreter: &Interpreter,
build_constraints: Constraints,
settings: &ResolverSettings,
network_settings: &NetworkSettings,
state: &PlatformState,
@ -1842,7 +1843,6 @@ pub(crate) async fn resolve_environment(
let extras = ExtrasSpecification::default();
let groups = BTreeMap::new();
let hasher = HashStrategy::default();
let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default();
// When resolving from an interpreter, we assume an empty environment, so reinstalls and

View file

@ -477,6 +477,7 @@ pub(crate) async fn install(
let resolution = resolve_environment(
spec.clone(),
&interpreter,
Constraints::from_requirements(build_constraints.iter().cloned()),
&settings.resolver,
&network_settings,
&state,
@ -530,6 +531,7 @@ pub(crate) async fn install(
match resolve_environment(
spec,
&interpreter,
Constraints::from_requirements(build_constraints.iter().cloned()),
&settings.resolver,
&network_settings,
&state,

View file

@ -298,6 +298,7 @@ async fn upgrade_tool(
let resolution = resolve_environment(
spec.into(),
interpreter,
build_constraints.clone(),
&settings.resolver,
network_settings,
&state,

View file

@ -1344,7 +1344,7 @@ fn run_with_build_constraints() -> Result<()> {
})?;
// Installing requests with incompatible build constraints should fail.
uv_snapshot!(context.filters(), context.run().arg("--with").arg("requests==1.2").arg("main.py"), @r###"
uv_snapshot!(context.filters(), context.run().arg("--with").arg("requests==1.2").arg("main.py"), @r"
success: false
exit_code: 1
----- stdout -----
@ -1358,12 +1358,11 @@ fn run_with_build_constraints() -> Result<()> {
+ idna==3.6
+ sniffio==1.3.1
+ typing-extensions==4.10.0
Resolved 1 package in [TIME]
× Failed to download and build `requests==1.2.0`
Failed to resolve requirements from `setup.py` build
No solution found when resolving: `setuptools>=40.8.0`
Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that your requirements are unsatisfiable.
"###);
");
// Change the build constraint to be compatible with `requests==1.2`.
pyproject_toml.write_str(indoc! { r#"

View file

@ -420,7 +420,6 @@ fn tool_install_with_incompatible_build_constraints() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved [N] packages in [TIME]
× Failed to download and build `requests==1.2.0`
Failed to resolve requirements from `setup.py` build
No solution found when resolving: `setuptools>=40.8.0`

View file

@ -2537,7 +2537,6 @@ fn tool_run_with_incompatible_build_constraints() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved [N] packages in [TIME]
× Failed to download and build `requests==1.2.0`
Failed to resolve requirements from `setup.py` build
No solution found when resolving: `setuptools>=40.8.0`