From 03de6c36e34032a754fd49ecbd300246954d8042 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 16 Jul 2025 09:48:16 -0400 Subject: [PATCH] Warn on invalid `uv.toml` when provided via direct path (#14653) ## Summary We validate the `uv.toml` when it's discovered automatically, but not when provided via `--config-file`. The same limitations exist, though -- I think the lack of enforcement is just an oversight. Closes https://github.com/astral-sh/uv/issues/14650. --- crates/uv-settings/src/lib.rs | 7 ++++++- crates/uv/tests/it/pip_install.rs | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/uv-settings/src/lib.rs b/crates/uv-settings/src/lib.rs index 54ae4e261..d676cc060 100644 --- a/crates/uv-settings/src/lib.rs +++ b/crates/uv-settings/src/lib.rs @@ -170,7 +170,12 @@ impl FilesystemOptions { /// Load a [`FilesystemOptions`] from a `uv.toml` file. pub fn from_file(path: impl AsRef) -> Result { - Ok(Self(read_file(path.as_ref())?)) + let path = path.as_ref(); + tracing::debug!("Reading user configuration from: `{}`", path.display()); + + let options = read_file(path)?; + validate_uv_toml(path, &options)?; + Ok(Self(options)) } } diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index bc27228c7..123d9066b 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -267,7 +267,7 @@ fn invalid_toml_filename() -> Result<()> { } #[test] -fn invalid_uv_toml_option_disallowed() -> Result<()> { +fn invalid_uv_toml_option_disallowed_automatic_discovery() -> Result<()> { let context = TestContext::new("3.12"); let uv_toml = context.temp_dir.child("uv.toml"); uv_toml.write_str(indoc! {r" @@ -288,6 +288,30 @@ fn invalid_uv_toml_option_disallowed() -> Result<()> { Ok(()) } +#[test] +fn invalid_uv_toml_option_disallowed_command_line() -> Result<()> { + let context = TestContext::new("3.12"); + let uv_toml = context.temp_dir.child("foo.toml"); + uv_toml.write_str(indoc! {r" + managed = true + "})?; + + uv_snapshot!(context.pip_install() + .arg("iniconfig") + .arg("--config-file") + .arg("foo.toml"), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: Failed to parse: `foo.toml`. The `managed` field is not allowed in a `uv.toml` file. `managed` is only applicable in the context of a project, and should be placed in a `pyproject.toml` file instead. + " + ); + + Ok(()) +} + #[test] fn cache_uv_toml_credentials() -> Result<()> { let context = TestContext::new("3.12");