-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove flatten
to improve deserialization error messages
#7598
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,15 @@ pub(crate) struct Tools { | |
/// A `[tool.uv]` section. | ||
#[allow(dead_code)] | ||
#[derive(Debug, Clone, Default, Deserialize, CombineOptions, OptionsMetadata)] | ||
#[serde(rename_all = "kebab-case", deny_unknown_fields)] | ||
#[serde(from = "OptionsWire", rename_all = "kebab-case")] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
pub struct Options { | ||
#[serde(flatten)] | ||
pub globals: GlobalOptions, | ||
|
||
#[serde(flatten)] | ||
pub top_level: ResolverInstallerOptions, | ||
|
||
#[option_group] | ||
pub pip: Option<PipOptions>, | ||
|
||
|
@@ -79,7 +81,6 @@ pub struct Options { | |
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }] | ||
"# | ||
)] | ||
#[serde(default, skip_serializing)] | ||
cache_keys: Option<Vec<CacheKey>>, | ||
|
||
// NOTE(charlie): These fields are shared with `ToolUv` in | ||
|
@@ -92,28 +93,6 @@ pub struct Options { | |
|
||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
pub environments: Option<SupportedEnvironments>, | ||
|
||
// NOTE(charlie): These fields should be kept in-sync with `ToolUv` in | ||
// `crates/uv-workspace/src/pyproject.rs`. | ||
#[serde(default, skip_serializing)] | ||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
workspace: serde::de::IgnoredAny, | ||
|
||
#[serde(default, skip_serializing)] | ||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
sources: serde::de::IgnoredAny, | ||
|
||
#[serde(default, skip_serializing)] | ||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
dev_dependencies: serde::de::IgnoredAny, | ||
|
||
#[serde(default, skip_serializing)] | ||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
managed: serde::de::IgnoredAny, | ||
|
||
#[serde(default, skip_serializing)] | ||
#[cfg_attr(feature = "schemars", schemars(skip))] | ||
r#package: serde::de::IgnoredAny, | ||
} | ||
|
||
impl Options { | ||
|
@@ -1472,3 +1451,171 @@ impl From<ToolOptions> for ResolverInstallerOptions { | |
} | ||
} | ||
} | ||
|
||
/// Like [`Options]`, but with any `#[serde(flatten)]` fields inlined. This leads to far, far | ||
/// better error messages when deserializing. | ||
#[derive(Debug, Clone, Default, Deserialize)] | ||
#[serde(rename_all = "kebab-case", deny_unknown_fields)] | ||
pub struct OptionsWire { | ||
// #[serde(flatten)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be commented? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, to indicate where the various sections start and end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's sort of confusing, but okay. |
||
// globals: GlobalOptions, | ||
native_tls: Option<bool>, | ||
offline: Option<bool>, | ||
no_cache: Option<bool>, | ||
cache_dir: Option<PathBuf>, | ||
preview: Option<bool>, | ||
python_preference: Option<PythonPreference>, | ||
python_downloads: Option<PythonDownloads>, | ||
concurrent_downloads: Option<NonZeroUsize>, | ||
concurrent_builds: Option<NonZeroUsize>, | ||
concurrent_installs: Option<NonZeroUsize>, | ||
|
||
// #[serde(flatten)] | ||
// top_level: ResolverInstallerOptions, | ||
index_url: Option<IndexUrl>, | ||
extra_index_url: Option<Vec<IndexUrl>>, | ||
no_index: Option<bool>, | ||
find_links: Option<Vec<FlatIndexLocation>>, | ||
index_strategy: Option<IndexStrategy>, | ||
keyring_provider: Option<KeyringProviderType>, | ||
allow_insecure_host: Option<Vec<TrustedHost>>, | ||
resolution: Option<ResolutionMode>, | ||
prerelease: Option<PrereleaseMode>, | ||
dependency_metadata: Option<Vec<StaticMetadata>>, | ||
config_settings: Option<ConfigSettings>, | ||
no_build_isolation: Option<bool>, | ||
no_build_isolation_package: Option<Vec<PackageName>>, | ||
exclude_newer: Option<ExcludeNewer>, | ||
link_mode: Option<LinkMode>, | ||
compile_bytecode: Option<bool>, | ||
no_sources: Option<bool>, | ||
upgrade: Option<bool>, | ||
upgrade_package: Option<Vec<Requirement<VerbatimParsedUrl>>>, | ||
reinstall: Option<bool>, | ||
reinstall_package: Option<Vec<PackageName>>, | ||
no_build: Option<bool>, | ||
no_build_package: Option<Vec<PackageName>>, | ||
no_binary: Option<bool>, | ||
no_binary_package: Option<Vec<PackageName>>, | ||
|
||
pip: Option<PipOptions>, | ||
cache_keys: Option<Vec<CacheKey>>, | ||
|
||
// NOTE(charlie): These fields are shared with `ToolUv` in | ||
// `crates/uv-workspace/src/pyproject.rs`, and the documentation lives on that struct. | ||
override_dependencies: Option<Vec<Requirement<VerbatimParsedUrl>>>, | ||
constraint_dependencies: Option<Vec<Requirement<VerbatimParsedUrl>>>, | ||
environments: Option<SupportedEnvironments>, | ||
|
||
// NOTE(charlie): These fields should be kept in-sync with `ToolUv` in | ||
// `crates/uv-workspace/src/pyproject.rs`. | ||
#[allow(dead_code)] | ||
workspace: Option<serde::de::IgnoredAny>, | ||
#[allow(dead_code)] | ||
sources: Option<serde::de::IgnoredAny>, | ||
#[allow(dead_code)] | ||
dev_dependencies: Option<serde::de::IgnoredAny>, | ||
#[allow(dead_code)] | ||
managed: Option<serde::de::IgnoredAny>, | ||
#[allow(dead_code)] | ||
r#package: Option<serde::de::IgnoredAny>, | ||
} | ||
|
||
impl From<OptionsWire> for Options { | ||
fn from(value: OptionsWire) -> Self { | ||
let OptionsWire { | ||
native_tls, | ||
offline, | ||
no_cache, | ||
cache_dir, | ||
preview, | ||
python_preference, | ||
python_downloads, | ||
concurrent_downloads, | ||
concurrent_builds, | ||
concurrent_installs, | ||
index_url, | ||
extra_index_url, | ||
no_index, | ||
find_links, | ||
index_strategy, | ||
keyring_provider, | ||
allow_insecure_host, | ||
resolution, | ||
prerelease, | ||
dependency_metadata, | ||
config_settings, | ||
no_build_isolation, | ||
no_build_isolation_package, | ||
exclude_newer, | ||
link_mode, | ||
compile_bytecode, | ||
no_sources, | ||
upgrade, | ||
upgrade_package, | ||
reinstall, | ||
reinstall_package, | ||
no_build, | ||
no_build_package, | ||
no_binary, | ||
no_binary_package, | ||
pip, | ||
cache_keys, | ||
override_dependencies, | ||
constraint_dependencies, | ||
environments, | ||
workspace: _, | ||
sources: _, | ||
dev_dependencies: _, | ||
managed: _, | ||
package: _, | ||
} = value; | ||
|
||
Self { | ||
globals: GlobalOptions { | ||
native_tls, | ||
offline, | ||
no_cache, | ||
cache_dir, | ||
preview, | ||
python_preference, | ||
python_downloads, | ||
concurrent_downloads, | ||
concurrent_builds, | ||
concurrent_installs, | ||
}, | ||
top_level: ResolverInstallerOptions { | ||
index_url, | ||
extra_index_url, | ||
no_index, | ||
find_links, | ||
index_strategy, | ||
keyring_provider, | ||
allow_insecure_host, | ||
resolution, | ||
prerelease, | ||
dependency_metadata, | ||
config_settings, | ||
no_build_isolation, | ||
no_build_isolation_package, | ||
exclude_newer, | ||
link_mode, | ||
compile_bytecode, | ||
no_sources, | ||
upgrade, | ||
upgrade_package, | ||
reinstall, | ||
reinstall_package, | ||
no_build, | ||
no_build_package, | ||
no_binary, | ||
no_binary_package, | ||
}, | ||
pip, | ||
cache_keys, | ||
override_dependencies, | ||
constraint_dependencies, | ||
environments, | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left these here because
schemars
uses them for the JSON schema.