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.
This commit is contained in:
Charlie Marsh 2025-07-16 09:48:16 -04:00 committed by GitHub
parent 861f7a1c42
commit 03de6c36e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View file

@ -170,7 +170,12 @@ impl FilesystemOptions {
/// Load a [`FilesystemOptions`] from a `uv.toml` file.
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {
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))
}
}

View file

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