Skip to content

Commit 9cf7821

Browse files
Gankrazanieb
authored andcommitted
Add missing validations for disallowed uv.toml fields (#14322)
We weren't following our usual "destructure all the options" pattern in this function, and several "this isn't actually read from uv.toml" fields slipped through the cracks over time since folks forgot it existed. Fixes part of #14308, although we could still try to make the warning in FilesystemOptions more accurate? You could argue this is a breaking change, but I think it ultimately isn't really, because we were already silently ignoring these fields. Now we properly error.
1 parent dbaec05 commit 9cf7821

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

crates/uv-settings/src/lib.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,71 @@ fn read_file(path: &Path) -> Result<Options, Error> {
201201

202202
/// Validate that an [`Options`] schema is compatible with `uv.toml`.
203203
fn validate_uv_toml(path: &Path, options: &Options) -> Result<(), Error> {
204+
let Options {
205+
globals: _,
206+
top_level: _,
207+
install_mirrors: _,
208+
publish: _,
209+
add: _,
210+
pip: _,
211+
cache_keys: _,
212+
override_dependencies: _,
213+
constraint_dependencies: _,
214+
build_constraint_dependencies: _,
215+
environments: _,
216+
required_environments: _,
217+
conflicts,
218+
workspace,
219+
sources,
220+
dev_dependencies,
221+
default_groups,
222+
dependency_groups,
223+
managed,
224+
package,
225+
build_backend,
226+
} = options;
204227
// The `uv.toml` format is not allowed to include any of the following, which are
205228
// permitted by the schema since they _can_ be included in `pyproject.toml` files
206229
// (and we want to use `deny_unknown_fields`).
207-
if options.workspace.is_some() {
230+
if conflicts.is_some() {
231+
return Err(Error::PyprojectOnlyField(path.to_path_buf(), "conflicts"));
232+
}
233+
if workspace.is_some() {
208234
return Err(Error::PyprojectOnlyField(path.to_path_buf(), "workspace"));
209235
}
210-
if options.sources.is_some() {
236+
if sources.is_some() {
211237
return Err(Error::PyprojectOnlyField(path.to_path_buf(), "sources"));
212238
}
213-
if options.dev_dependencies.is_some() {
239+
if dev_dependencies.is_some() {
214240
return Err(Error::PyprojectOnlyField(
215241
path.to_path_buf(),
216242
"dev-dependencies",
217243
));
218244
}
219-
if options.default_groups.is_some() {
245+
if default_groups.is_some() {
220246
return Err(Error::PyprojectOnlyField(
221247
path.to_path_buf(),
222248
"default-groups",
223249
));
224250
}
225-
if options.managed.is_some() {
251+
if dependency_groups.is_some() {
252+
return Err(Error::PyprojectOnlyField(
253+
path.to_path_buf(),
254+
"dependency-groups",
255+
));
256+
}
257+
if managed.is_some() {
226258
return Err(Error::PyprojectOnlyField(path.to_path_buf(), "managed"));
227259
}
228-
if options.package.is_some() {
260+
if package.is_some() {
229261
return Err(Error::PyprojectOnlyField(path.to_path_buf(), "package"));
230262
}
263+
if build_backend.is_some() {
264+
return Err(Error::PyprojectOnlyField(
265+
path.to_path_buf(),
266+
"build-backend",
267+
));
268+
}
231269
Ok(())
232270
}
233271

crates/uv-settings/src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct Options {
103103
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = { commit = true } }]
104104
"#
105105
)]
106-
cache_keys: Option<Vec<CacheKey>>,
106+
pub cache_keys: Option<Vec<CacheKey>>,
107107

108108
// NOTE(charlie): These fields are shared with `ToolUv` in
109109
// `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct.

0 commit comments

Comments
 (0)