mirror of https://github.com/astral-sh/uv
Respect self-constraints on recursive extras (#9714)
## Summary
Sort of ridiculous, but today this passes, when it should fail:
```toml
[project]
name = "foo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13.0"
dependencies = []
[project.optional-dependencies]
async = [
"foo[async]==0.2.0",
]
```
This commit is contained in:
parent
1b4bd8d3b7
commit
00a4adfc46
|
|
@ -562,6 +562,16 @@ impl RequirementSource {
|
||||||
matches!(self, Self::Directory { editable: true, .. })
|
matches!(self, Self::Directory { editable: true, .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the source is empty.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Registry { specifier, .. } => specifier.is_empty(),
|
||||||
|
Self::Url { .. } | Self::Git { .. } | Self::Path { .. } | Self::Directory { .. } => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If the source is the registry, return the version specifiers
|
/// If the source is the registry, return the version specifiers
|
||||||
pub fn version_specifiers(&self) -> Option<&VersionSpecifiers> {
|
pub fn version_specifiers(&self) -> Option<&VersionSpecifiers> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
||||||
|
|
@ -1328,7 +1328,7 @@ impl std::fmt::Display for PubGrubHint {
|
||||||
Self::DependsOnItself { package } => {
|
Self::DependsOnItself { package } => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}{} The package `{}` depends on itself. This is likely a mistake. Consider removing the dependency.",
|
"{}{} The package `{}` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.",
|
||||||
"hint".bold().cyan(),
|
"hint".bold().cyan(),
|
||||||
":".bold(),
|
":".bold(),
|
||||||
package.cyan(),
|
package.cyan(),
|
||||||
|
|
|
||||||
|
|
@ -1567,7 +1567,8 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
||||||
return requirements;
|
return requirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are recursive self inclusions and we need to go into the expensive branch.
|
// Check if there are recursive self inclusions; if so, we need to go into the expensive
|
||||||
|
// branch.
|
||||||
if !requirements
|
if !requirements
|
||||||
.iter()
|
.iter()
|
||||||
.any(|req| name == Some(&req.name) && !req.extras.is_empty())
|
.any(|req| name == Some(&req.name) && !req.extras.is_empty())
|
||||||
|
|
@ -1624,8 +1625,26 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retain any self-constraints for that extra, e.g., if `project[foo]` includes
|
||||||
|
// `project[bar]>1.0`, as a dependency, we need to propagate `project>1.0`, in addition to
|
||||||
|
// transitively expanding `project[bar]`.
|
||||||
|
let mut self_constraints = vec![];
|
||||||
|
for req in &requirements {
|
||||||
|
if name == Some(&req.name) && !req.source.is_empty() {
|
||||||
|
self_constraints.push(Requirement {
|
||||||
|
name: req.name.clone(),
|
||||||
|
extras: vec![],
|
||||||
|
groups: req.groups.clone(),
|
||||||
|
source: req.source.clone(),
|
||||||
|
origin: req.origin.clone(),
|
||||||
|
marker: req.marker,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Drop all the self-requirements now that we flattened them out.
|
// Drop all the self-requirements now that we flattened them out.
|
||||||
requirements.retain(|req| name != Some(&req.name));
|
requirements.retain(|req| name != Some(&req.name) || req.extras.is_empty());
|
||||||
|
requirements.extend(self_constraints.into_iter().map(Cow::Owned));
|
||||||
|
|
||||||
requirements
|
requirements
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19457,7 +19457,7 @@ fn lock_self_incompatible() -> Result<()> {
|
||||||
× No solution found when resolving dependencies:
|
× No solution found when resolving dependencies:
|
||||||
╰─▶ Because your project depends on itself at an incompatible version (project==0.2.0), we can conclude that your project's requirements are unsatisfiable.
|
╰─▶ Because your project depends on itself at an incompatible version (project==0.2.0), we can conclude that your project's requirements are unsatisfiable.
|
||||||
|
|
||||||
hint: The package `project` depends on itself. This is likely a mistake. Consider removing the dependency.
|
hint: The package `project` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -19566,10 +19566,9 @@ fn lock_self_extra_to_extra_compatible() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lock_self_extra_to_extra_incompatible() -> Result<()> {
|
fn lock_self_extra_to_same_extra_incompatible() -> Result<()> {
|
||||||
let context = TestContext::new("3.12");
|
let context = TestContext::new("3.12");
|
||||||
|
|
||||||
// TODO(charlie): This should fail, but currently succeeds.
|
|
||||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||||
pyproject_toml.write_str(
|
pyproject_toml.write_str(
|
||||||
r#"
|
r#"
|
||||||
|
|
@ -19585,52 +19584,50 @@ fn lock_self_extra_to_extra_incompatible() -> Result<()> {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
uv_snapshot!(context.filters(), context.lock(), @r###"
|
uv_snapshot!(context.filters(), context.lock(), @r###"
|
||||||
success: true
|
success: false
|
||||||
exit_code: 0
|
exit_code: 1
|
||||||
----- stdout -----
|
----- stdout -----
|
||||||
|
|
||||||
----- stderr -----
|
----- stderr -----
|
||||||
Resolved 2 packages in [TIME]
|
× No solution found when resolving dependencies:
|
||||||
|
╰─▶ Because project[foo] depends on your project and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
|
||||||
|
|
||||||
|
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
let lock = context.read("uv.lock");
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
insta::with_settings!({
|
#[test]
|
||||||
filters => context.filters(),
|
fn lock_self_extra_to_other_extra_incompatible() -> Result<()> {
|
||||||
}, {
|
let context = TestContext::new("3.12");
|
||||||
assert_snapshot!(
|
|
||||||
lock, @r###"
|
|
||||||
version = 1
|
|
||||||
requires-python = ">=3.12"
|
|
||||||
|
|
||||||
[options]
|
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||||
exclude-newer = "2024-03-25T00:00:00Z"
|
pyproject_toml.write_str(
|
||||||
|
r#"
|
||||||
[[package]]
|
[project]
|
||||||
name = "project"
|
name = "project"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = ["typing-extensions"]
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.metadata]
|
[project.optional-dependencies]
|
||||||
requires-dist = [
|
foo = ["project[bar]==0.2.0"]
|
||||||
{ name = "project", extras = ["foo"], marker = "extra == 'foo'", specifier = "==0.2.0" },
|
bar = ["iniconfig"]
|
||||||
{ name = "typing-extensions" },
|
"#,
|
||||||
]
|
)?;
|
||||||
|
|
||||||
[[package]]
|
uv_snapshot!(context.filters(), context.lock(), @r###"
|
||||||
name = "typing-extensions"
|
success: false
|
||||||
version = "4.10.0"
|
exit_code: 1
|
||||||
source = { registry = "https://pypi.org/simple" }
|
----- stdout -----
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb", size = 77558 }
|
|
||||||
wheels = [
|
----- stderr -----
|
||||||
{ url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl", hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", size = 33926 },
|
× No solution found when resolving dependencies:
|
||||||
]
|
╰─▶ Because project[foo] depends on your project and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
|
||||||
"###
|
|
||||||
);
|
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
|
||||||
});
|
"###);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -19764,7 +19761,7 @@ fn lock_self_extra_incompatible() -> Result<()> {
|
||||||
× No solution found when resolving dependencies:
|
× No solution found when resolving dependencies:
|
||||||
╰─▶ Because project[foo] depends on your project and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
|
╰─▶ Because project[foo] depends on your project and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
|
||||||
|
|
||||||
hint: The package `project[foo]` depends on itself. This is likely a mistake. Consider removing the dependency.
|
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -19893,7 +19890,7 @@ fn lock_self_marker_incompatible() -> Result<()> {
|
||||||
× No solution found when resolving dependencies:
|
× No solution found when resolving dependencies:
|
||||||
╰─▶ Because only project{sys_platform == 'win32'}<=0.1 is available and your project depends on project{sys_platform == 'win32'}>0.1, we can conclude that your project's requirements are unsatisfiable.
|
╰─▶ Because only project{sys_platform == 'win32'}<=0.1 is available and your project depends on project{sys_platform == 'win32'}>0.1, we can conclude that your project's requirements are unsatisfiable.
|
||||||
|
|
||||||
hint: The package `project` depends on itself. This is likely a mistake. Consider removing the dependency.
|
hint: The package `project` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue