Generate API reference for options documentation (#5072)

## Summary

Generates Markdown from the `OptionsMetadata`, following the same
strategy as in Ruff.

## Test Plan

`cargo dev generate-options-reference`
This commit is contained in:
Charlie Marsh 2024-07-15 15:48:40 -04:00 committed by GitHub
parent 1b1eba12c7
commit 6275b54d51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 343 additions and 22 deletions

View file

@ -26,7 +26,9 @@ uv-configuration = { workspace = true }
uv-extract = { workspace = true }
uv-fs = { workspace = true, features = ["tokio"] }
uv-git = { workspace = true }
uv-macros = { workspace = true }
uv-normalize = { workspace = true }
uv-options-metadata = { workspace = true }
uv-types = { workspace = true }
uv-warnings = { workspace = true }
@ -61,3 +63,6 @@ regex = { workspace = true }
[features]
schemars = ["dep:schemars"]
[package.metadata.cargo-shear]
ignored = ["uv-options-metadata"]

View file

@ -17,6 +17,7 @@ use url::Url;
use pep440_rs::VersionSpecifiers;
use pypi_types::{RequirementSource, VerbatimParsedUrl};
use uv_git::GitReference;
use uv_macros::OptionsMetadata;
use uv_normalize::{ExtraName, PackageName};
/// A `pyproject.toml` as specified in PEP 517.
@ -69,15 +70,23 @@ pub struct Tool {
pub uv: Option<ToolUv>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, OptionsMetadata, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ToolUv {
pub sources: Option<BTreeMap<PackageName, Source>>,
/// The workspace definition for the project, if any.
#[option_group]
pub workspace: Option<ToolUvWorkspace>,
/// Whether the project is managed by `uv`. If `false`, `uv` will ignore the project when
/// `uv run` is invoked.
#[option(
default = r#"true"#,
value_type = "bool",
example = r#"
managed = false
"#
)]
pub managed: Option<bool>,
#[cfg_attr(
feature = "schemars",
@ -97,10 +106,35 @@ pub struct ToolUv {
pub override_dependencies: Option<Vec<pep508_rs::Requirement<VerbatimParsedUrl>>>,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, OptionsMetadata, Default, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct ToolUvWorkspace {
/// Packages to include as workspace members.
///
/// Supports both globs and explicit paths.
///
/// For more information on the glob syntax, refer to the [`glob` documentation](https://docs.rs/glob/latest/glob/struct.Pattern.html).
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
members = ["member1", "path/to/member2", "libs/*"]
"#
)]
pub members: Option<Vec<SerdePattern>>,
/// Packages to exclude as workspace members. If a package matches both `members` and
/// `exclude`, it will be excluded.
///
/// Supports both globs and explicit paths.
///
/// For more information on the glob syntax, refer to the [`glob` documentation](https://docs.rs/glob/latest/glob/struct.Pattern.html).
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"
exclude = ["member1", "path/to/member2", "libs/*"]
"#
)]
pub exclude: Option<Vec<SerdePattern>>,
}