Skip to content

Commit 3cdcbae

Browse files
committed
Error when pyproject.toml target does not exist for dependency groups
1 parent f59d00b commit 3cdcbae

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

crates/uv-distribution/src/metadata/dependency_groups.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ impl SourcedDependencyGroups {
5858
source_strategy: SourceStrategy,
5959
cache: &WorkspaceCache,
6060
) -> Result<Self, MetadataError> {
61+
// If the `pyproject.toml` doesn't exist, fail early.
62+
if !pyproject_path.is_file() {
63+
return Err(MetadataError::MissingPyprojectToml(
64+
pyproject_path.to_path_buf(),
65+
));
66+
}
67+
6168
let discovery = DiscoveryOptions {
6269
stop_discovery_at: git_member.map(|git_member| {
6370
git_member

crates/uv-distribution/src/metadata/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::BTreeMap;
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
33

44
use thiserror::Error;
55

@@ -28,6 +28,8 @@ pub enum MetadataError {
2828
Workspace(#[from] WorkspaceError),
2929
#[error(transparent)]
3030
DependencyGroup(#[from] DependencyGroupError),
31+
#[error("No pyproject.toml found at `{0}`")]
32+
MissingPyprojectToml(PathBuf),
3133
#[error("Failed to parse entry: `{0}`")]
3234
LoweringError(PackageName, #[source] Box<LoweringError>),
3335
#[error("Failed to parse entry in group `{0}`: `{1}`")]

crates/uv/src/commands/pip/operations.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ pub(crate) async fn resolve<InstalledPackages: InstalledPackagesProvider>(
218218
.await
219219
.with_context(|| {
220220
format!(
221-
"Failed to read dependency groups from: {}",
222-
pyproject_path.display()
221+
"Failed to read dependency groups from: `{}`",
222+
pyproject_path.user_display()
223223
)
224224
})?;
225225

226226
// Complain if dependency groups are named that don't appear.
227227
for name in groups.explicit_names() {
228228
if !metadata.dependency_groups.contains_key(name) {
229229
return Err(anyhow!(
230-
"The dependency group '{name}' was not found in the project: {}",
230+
"The dependency group '{name}' was not found in the project: `{}`",
231231
pyproject_path.user_display()
232232
))?;
233233
}

crates/uv/tests/it/pip_compile.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16179,6 +16179,36 @@ fn directory_and_group() -> Result<()> {
1617916179
Ok(())
1618016180
}
1618116181

16182+
#[test]
16183+
fn group_target_does_not_exist() -> Result<()> {
16184+
let context = TestContext::new("3.12");
16185+
16186+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
16187+
pyproject_toml.write_str(
16188+
r#"
16189+
[project]
16190+
name = "myproject"
16191+
version = "0.1.0"
16192+
requires-python = ">=3.12"
16193+
16194+
16195+
"#,
16196+
)?;
16197+
16198+
uv_snapshot!(context.filters(), context.pip_compile()
16199+
.arg("--group").arg("does/not/exist/pyproject.toml:foo"), @r"
16200+
success: false
16201+
exit_code: 2
16202+
----- stdout -----
16203+
16204+
----- stderr -----
16205+
error: Failed to read dependency groups from: `does/not/exist/pyproject.toml`
16206+
Caused by: No pyproject.toml found at `does/not/exist/pyproject.toml`
16207+
");
16208+
16209+
Ok(())
16210+
}
16211+
1618216212
/// See: <https://github.com/astral-sh/uv/issues/10957>
1618316213
#[cfg(feature = "python-eol")]
1618416214
#[test]

0 commit comments

Comments
 (0)