Skip to content

Commit 510c5f0

Browse files
committed
Add warnings for undefined groups
1 parent 9247f2f commit 510c5f0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

crates/uv-requirements/src/source_tree.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use uv_pep508::RequirementOrigin;
1818
use uv_pypi_types::Requirement;
1919
use uv_resolver::{InMemoryIndex, MetadataResponse};
2020
use uv_types::{BuildContext, HashStrategy};
21-
21+
use uv_warnings::warn_user_once;
2222
#[derive(Debug, Clone)]
2323
pub struct SourceTreeResolution {
2424
/// The requirements sourced from the source trees.
@@ -115,6 +115,20 @@ impl<'a, Context: BuildContext> SourceTreeResolver<'a, Context> {
115115
requirements.extend(group.iter().cloned());
116116
}
117117
}
118+
// Complain if dependency groups are named that don't appear.
119+
// This is only a warning because *technically* we support passing in
120+
// multiple pyproject.tomls, but at this level of abstraction we can't see them all,
121+
// so hard erroring on "no pyproject.toml mentions this" is a bit difficult.
122+
if let Some(groups) = self.groups.groups() {
123+
for name in groups.names() {
124+
if !metadata.dependency_groups.contains_key(name) {
125+
warn_user_once!(
126+
"The dependency-group '{name}' is not defined in {}",
127+
path.display()
128+
);
129+
}
130+
}
131+
}
118132

119133
let project = metadata.name;
120134
let extras = metadata.provides_extras;

crates/uv/tests/it/pip_install.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8610,13 +8610,30 @@ fn install_many_pyproject_group() -> Result<()> {
86108610
----- stdout -----
86118611
86128612
----- stderr -----
8613+
warning: The dependency-group 'bar' is not defined in pyproject.toml
86138614
Resolved 2 packages in [TIME]
86148615
Prepared 2 packages in [TIME]
86158616
Installed 2 packages in [TIME]
86168617
+ sniffio==1.3.1
86178618
+ typing-extensions==4.10.0
86188619
"###);
86198620

8621+
context = new_context()?;
8622+
uv_snapshot!(context.filters(), context.pip_install().arg("-r")
8623+
.arg("pyproject.toml").arg("-r").arg("subdir/pyproject.toml").arg("--group").arg("lies"), @r###"
8624+
success: true
8625+
exit_code: 0
8626+
----- stdout -----
8627+
8628+
----- stderr -----
8629+
warning: The dependency-group 'lies' is not defined in pyproject.toml
8630+
warning: The dependency-group 'lies' is not defined in subdir/pyproject.toml
8631+
Resolved 1 package in [TIME]
8632+
Prepared 1 package in [TIME]
8633+
Installed 1 package in [TIME]
8634+
+ typing-extensions==4.10.0
8635+
"###);
8636+
86208637
context = new_context()?;
86218638
uv_snapshot!(context.filters(), context.pip_install().arg("-r")
86228639
.arg("pyproject.toml").arg("-r").arg("subdir/pyproject.toml").arg("--group").arg("foo").arg("--group").arg("bar"), @r###"
@@ -8625,6 +8642,7 @@ fn install_many_pyproject_group() -> Result<()> {
86258642
----- stdout -----
86268643
86278644
----- stderr -----
8645+
warning: The dependency-group 'bar' is not defined in pyproject.toml
86288646
Resolved 4 packages in [TIME]
86298647
Prepared 4 packages in [TIME]
86308648
Installed 4 packages in [TIME]

0 commit comments

Comments
 (0)