Skip to content

Commit 3c813cd

Browse files
Error when pyproject.toml target does not exist for dependency groups (#15831)
## Summary Closes #15789.
1 parent b770639 commit 3c813cd

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
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/tests/it/pip_compile.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16179,6 +16179,34 @@ 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 = "uv%%%"
16191+
version = "0.1.0"
16192+
requires-python = ">=3.12"
16193+
"#,
16194+
)?;
16195+
16196+
uv_snapshot!(context.filters(), context.pip_compile()
16197+
.arg("--group").arg("does/not/exist/pyproject.toml:foo"), @r"
16198+
success: false
16199+
exit_code: 2
16200+
----- stdout -----
16201+
16202+
----- stderr -----
16203+
error: Failed to read dependency groups from: does/not/exist/pyproject.toml
16204+
Caused by: No pyproject.toml found at: does/not/exist/pyproject.toml
16205+
");
16206+
16207+
Ok(())
16208+
}
16209+
1618216210
/// See: <https://github.com/astral-sh/uv/issues/10957>
1618316211
#[cfg(feature = "python-eol")]
1618416212
#[test]

0 commit comments

Comments
 (0)