diff --git a/crates/uv/src/commands/pip/operations.rs b/crates/uv/src/commands/pip/operations.rs index 7db3d6a88..58a614f6f 100644 --- a/crates/uv/src/commands/pip/operations.rs +++ b/crates/uv/src/commands/pip/operations.rs @@ -215,11 +215,10 @@ pub(crate) async fn resolve( build_dispatch.workspace_cache(), ) .await - .map_err(|e| { - anyhow!( - "Failed to read dependency groups from: {}\n{}", - pyproject_path.display(), - e + .with_context(|| { + format!( + "Failed to read dependency groups from: {}", + pyproject_path.display() ) })?; diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index af6c4aee8..04e2be938 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -9719,6 +9719,74 @@ fn dependency_group() -> Result<()> { Ok(()) } +#[test] +fn recursive_dependency_group() -> Result<()> { + let context = TestContext::new("3.12"); + + // Test a self-referencing group. + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "myproject" + version = "0.1.0" + requires-python = ">=3.12" + + [dependency-groups] + test = [ + { include-group = "test" }, + "requests" + ] + "#, + )?; + + uv_snapshot!(context.filters(), context.pip_install() + .arg("--group").arg("test"), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: Failed to read dependency groups from: [TEMP_DIR]/pyproject.toml + Caused by: Project `myproject` has malformed dependency groups + Caused by: Detected a cycle in `dependency-groups`: `test` -> `test` + "); + + // Test mutually recursive groups. + pyproject_toml.write_str( + r#" + [project] + name = "myproject" + version = "0.1.0" + requires-python = ">=3.12" + + [dependency-groups] + test = [ + { include-group = "dev" }, + "requests" + ] + dev = [ + { include-group = "test" }, + "pytest" + ] + "#, + )?; + + uv_snapshot!(context.filters(), context.pip_install() + .arg("--group").arg("test"), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: Failed to read dependency groups from: [TEMP_DIR]/pyproject.toml + Caused by: Project `myproject` has malformed dependency groups + Caused by: Detected a cycle in `dependency-groups`: `dev` -> `test` -> `dev` + "); + + Ok(()) +} + #[test] fn virtual_dependency_group() -> Result<()> { // testing basic `uv pip install --group` functionality