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");