From c162fd51b85b327c74c6c25d2653151bb20afa19 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 24 Oct 2024 16:41:57 -0400 Subject: [PATCH 1/2] Add tool.uv.sources to the Settings reference --- crates/uv-settings/src/settings.rs | 9 ++++++--- crates/uv-workspace/src/pyproject.rs | 19 +++++++++++++++++-- docs/reference/settings.md | 26 ++++++++++++++++++++++++++ uv.schema.json | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/crates/uv-settings/src/settings.rs b/crates/uv-settings/src/settings.rs index ec880f390686..7080abe4e705 100644 --- a/crates/uv-settings/src/settings.rs +++ b/crates/uv-settings/src/settings.rs @@ -86,7 +86,8 @@ pub struct Options { cache_keys: Option>, // NOTE(charlie): These fields are shared with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`, and the documentation lives on that struct. + // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. + // They're respected in both `pyproject.toml` and `uv.toml` files. #[cfg_attr(feature = "schemars", schemars(skip))] pub override_dependencies: Option>>, @@ -1551,13 +1552,15 @@ pub struct OptionsWire { cache_keys: Option>, // NOTE(charlie): These fields are shared with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`, and the documentation lives on that struct. + // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. + // They're respected in both `pyproject.toml` and `uv.toml` files. override_dependencies: Option>>, constraint_dependencies: Option>>, environments: Option, // NOTE(charlie): These fields should be kept in-sync with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`. + // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. + // They're only respected in `pyproject.toml` files, and should be rejected in `uv.toml` files. #[allow(dead_code)] workspace: Option, #[allow(dead_code)] diff --git a/crates/uv-workspace/src/pyproject.rs b/crates/uv-workspace/src/pyproject.rs index 16d27a0eab53..906b2acfe4fb 100644 --- a/crates/uv-workspace/src/pyproject.rs +++ b/crates/uv-workspace/src/pyproject.rs @@ -152,8 +152,23 @@ pub struct Tool { #[serde(rename_all = "kebab-case")] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ToolUv { - /// The sources to use (e.g., workspace members, Git repositories, local paths) when resolving - /// dependencies. + /// The sources to use when resolving dependencies. + /// + /// `tool.uv.sources` enriches the dependency metadata with additional sources, incorporated + /// during development. A dependency source can be a Git repository, a URL, a local path, or an + /// alternative registry. + /// + /// See [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more. + #[option( + default = "\"[]\"", + value_type = "dict", + example = r#" + [tool.uv.sources] + httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" } + pytest = { url = "https://files.pythonhosted.org/packages/6b/77/7440a06a8ead44c7757a64362dd22df5760f9b12dc5f11b6188cd2fc27a0/pytest-8.3.3-py3-none-any.whl" } + pydantic = { path = "/path/to/pydantic", editable = true } + "# + )] pub sources: Option, /// The indexes to use when resolving dependencies. diff --git a/docs/reference/settings.md b/docs/reference/settings.md index ab44bb672499..72a80157ec82 100644 --- a/docs/reference/settings.md +++ b/docs/reference/settings.md @@ -198,6 +198,32 @@ package = false --- +### [`sources`](#sources) {: #sources } + +The sources to use when resolving dependencies. + +`tool.uv.sources` enriches the dependency metadata with additional sources, incorporated +during development. A dependency source can be a Git repository, a URL, a local path, or an +alternative registry. + +See [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more. + +**Default value**: `"[]"` + +**Type**: `dict` + +**Example usage**: + +```toml title="pyproject.toml" +[tool.uv] +[tool.uv.sources] +httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" } +pytest = { url = "https://files.pythonhosted.org/packages/6b/77/7440a06a8ead44c7757a64362dd22df5760f9b12dc5f11b6188cd2fc27a0/pytest-8.3.3-py3-none-any.whl" } +pydantic = { path = "/path/to/pydantic", editable = true } +``` + +--- + ### `workspace` #### [`exclude`](#workspace_exclude) {: #workspace_exclude } diff --git a/uv.schema.json b/uv.schema.json index 9df68ae4d042..9891e21733c2 100644 --- a/uv.schema.json +++ b/uv.schema.json @@ -398,7 +398,7 @@ ] }, "sources": { - "description": "The sources to use (e.g., workspace members, Git repositories, local paths) when resolving dependencies.", + "description": "The sources to use when resolving dependencies.\n\n`tool.uv.sources` enriches the dependency metadata with additional sources, incorporated during development. A dependency source can be a Git repository, a URL, a local path, or an alternative registry.\n\nSee [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more.", "anyOf": [ { "$ref": "#/definitions/ToolUvSources" From d8f4ea79228bab5435a91357356a377e4fefddbc Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 24 Oct 2024 16:51:09 -0400 Subject: [PATCH 2/2] Revert --- crates/uv-dev/src/generate_cli_reference.rs | 9 +++++- crates/uv-dev/src/generate_json_schema.rs | 31 +++++++++++++++++++-- crates/uv-settings/src/settings.rs | 9 ++---- crates/uv-workspace/src/pyproject.rs | 2 +- docs/reference/settings.md | 4 +-- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/crates/uv-dev/src/generate_cli_reference.rs b/crates/uv-dev/src/generate_cli_reference.rs index f036053cecf5..484ddf7569e6 100644 --- a/crates/uv-dev/src/generate_cli_reference.rs +++ b/crates/uv-dev/src/generate_cli_reference.rs @@ -101,7 +101,14 @@ fn generate() -> String { generate_command(&mut output, &uv, &mut parents); for (value, replacement) in REPLACEMENTS { - output = output.replace(value, replacement); + assert_ne!( + value, replacement, + "`value` and `replacement` must be different, but both are `{value}`" + ); + let before = &output; + let after = output.replace(value, replacement); + assert_ne!(*before, after, "Could not find `{value}` in the output"); + output = after; } output diff --git a/crates/uv-dev/src/generate_json_schema.rs b/crates/uv-dev/src/generate_json_schema.rs index 2fcf5d5d8cd2..50a89de18ad3 100644 --- a/crates/uv-dev/src/generate_json_schema.rs +++ b/crates/uv-dev/src/generate_json_schema.rs @@ -33,8 +33,8 @@ pub(crate) struct Args { } pub(crate) fn main(args: &Args) -> Result<()> { - let schema = schema_for!(CombinedOptions); - let schema_string = serde_json::to_string_pretty(&schema).unwrap(); + // Generate the schema. + let schema_string = generate(); let filename = "uv.schema.json"; let schema_path = PathBuf::from(ROOT_DIR).join(filename); @@ -80,5 +80,32 @@ pub(crate) fn main(args: &Args) -> Result<()> { Ok(()) } +const REPLACEMENTS: &[(&str, &str)] = &[ + // Use the fully-resolved URL rather than the relative Markdown path. + ( + "(../concepts/dependencies.md)", + "(https://docs.astral.sh/uv/concepts/dependencies/)", + ), +]; + +/// Generate the JSON schema for the combined options as a string. +fn generate() -> String { + let schema = schema_for!(CombinedOptions); + let mut output = serde_json::to_string_pretty(&schema).unwrap(); + + for (value, replacement) in REPLACEMENTS { + assert_ne!( + value, replacement, + "`value` and `replacement` must be different, but both are `{value}`" + ); + let before = &output; + let after = output.replace(value, replacement); + assert_ne!(*before, after, "Could not find `{value}` in the output"); + output = after; + } + + output +} + #[cfg(test)] mod tests; diff --git a/crates/uv-settings/src/settings.rs b/crates/uv-settings/src/settings.rs index 7080abe4e705..ec880f390686 100644 --- a/crates/uv-settings/src/settings.rs +++ b/crates/uv-settings/src/settings.rs @@ -86,8 +86,7 @@ pub struct Options { cache_keys: Option>, // NOTE(charlie): These fields are shared with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. - // They're respected in both `pyproject.toml` and `uv.toml` files. + // `crates/uv-workspace/src/pyproject.rs`, and the documentation lives on that struct. #[cfg_attr(feature = "schemars", schemars(skip))] pub override_dependencies: Option>>, @@ -1552,15 +1551,13 @@ pub struct OptionsWire { cache_keys: Option>, // NOTE(charlie): These fields are shared with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. - // They're respected in both `pyproject.toml` and `uv.toml` files. + // `crates/uv-workspace/src/pyproject.rs`, and the documentation lives on that struct. override_dependencies: Option>>, constraint_dependencies: Option>>, environments: Option, // NOTE(charlie): These fields should be kept in-sync with `ToolUv` in - // `crates/uv-workspace/src/pyproject.rs`. The documentation lives on that struct. - // They're only respected in `pyproject.toml` files, and should be rejected in `uv.toml` files. + // `crates/uv-workspace/src/pyproject.rs`. #[allow(dead_code)] workspace: Option, #[allow(dead_code)] diff --git a/crates/uv-workspace/src/pyproject.rs b/crates/uv-workspace/src/pyproject.rs index 906b2acfe4fb..99d7cebde468 100644 --- a/crates/uv-workspace/src/pyproject.rs +++ b/crates/uv-workspace/src/pyproject.rs @@ -158,7 +158,7 @@ pub struct ToolUv { /// during development. A dependency source can be a Git repository, a URL, a local path, or an /// alternative registry. /// - /// See [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more. + /// See [Dependencies](../concepts/dependencies.md) for more. #[option( default = "\"[]\"", value_type = "dict", diff --git a/docs/reference/settings.md b/docs/reference/settings.md index 72a80157ec82..cad97ebb243f 100644 --- a/docs/reference/settings.md +++ b/docs/reference/settings.md @@ -206,7 +206,7 @@ The sources to use when resolving dependencies. during development. A dependency source can be a Git repository, a URL, a local path, or an alternative registry. -See [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more. +See [Dependencies](../concepts/dependencies.md) for more. **Default value**: `"[]"` @@ -215,7 +215,7 @@ See [Dependencies](https://docs.astral.sh/uv/concepts/dependencies/) for more. **Example usage**: ```toml title="pyproject.toml" -[tool.uv] + [tool.uv.sources] httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" } pytest = { url = "https://files.pythonhosted.org/packages/6b/77/7440a06a8ead44c7757a64362dd22df5760f9b12dc5f11b6188cd2fc27a0/pytest-8.3.3-py3-none-any.whl" }