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( resolve_environment(
spec, spec,
&interpreter, &interpreter,
build_constraints.clone(),
&settings.resolver, &settings.resolver,
network_settings, network_settings,
state, state,

View file

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

View file

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

View file

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

View file

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

View file

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