Skip to content

Commit 84ce454

Browse files
committed
Warn on invalid uv.toml when provided via direct path
1 parent 8d6d067 commit 84ce454

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

crates/uv-settings/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ impl FilesystemOptions {
170170

171171
/// Load a [`FilesystemOptions`] from a `uv.toml` file.
172172
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {
173-
Ok(Self(read_file(path.as_ref())?))
173+
let path = path.as_ref();
174+
tracing::debug!("Reading user configuration from: `{}`", path.display());
175+
176+
let options = read_file(path)?;
177+
validate_uv_toml(path, &options)?;
178+
Ok(Self(options))
174179
}
175180
}
176181

crates/uv/tests/it/pip_install.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn invalid_toml_filename() -> Result<()> {
267267
}
268268

269269
#[test]
270-
fn invalid_uv_toml_option_disallowed() -> Result<()> {
270+
fn invalid_uv_toml_option_disallowed_automatic_discovery() -> Result<()> {
271271
let context = TestContext::new("3.12");
272272
let uv_toml = context.temp_dir.child("uv.toml");
273273
uv_toml.write_str(indoc! {r"
@@ -288,6 +288,30 @@ fn invalid_uv_toml_option_disallowed() -> Result<()> {
288288
Ok(())
289289
}
290290

291+
#[test]
292+
fn invalid_uv_toml_option_disallowed_command_line() -> Result<()> {
293+
let context = TestContext::new("3.12");
294+
let uv_toml = context.temp_dir.child("foo.toml");
295+
uv_toml.write_str(indoc! {r"
296+
managed = true
297+
"})?;
298+
299+
uv_snapshot!(context.pip_install()
300+
.arg("iniconfig")
301+
.arg("--config-file")
302+
.arg("foo.toml"), @r"
303+
success: false
304+
exit_code: 2
305+
----- stdout -----
306+
307+
----- stderr -----
308+
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.
309+
"
310+
);
311+
312+
Ok(())
313+
}
314+
291315
#[test]
292316
fn cache_uv_toml_credentials() -> Result<()> {
293317
let context = TestContext::new("3.12");

0 commit comments

Comments
 (0)