Skip to content

Commit

Permalink
Add tool.uv.sources to the "Settings" reference (#8543)
Browse files Browse the repository at this point in the history
## Summary

Closes #8540.
  • Loading branch information
charliermarsh authored Oct 24, 2024
1 parent 99a8746 commit 58b5fd4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
9 changes: 8 additions & 1 deletion crates/uv-dev/src/generate_cli_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 29 additions & 2 deletions crates/uv-dev/src/generate_json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
19 changes: 17 additions & 2 deletions crates/uv-workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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](../concepts/dependencies.md) 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<ToolUvSources>,

/// The indexes to use when resolving dependencies.
Expand Down
26 changes: 26 additions & 0 deletions docs/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](../concepts/dependencies.md) for more.

**Default value**: `"[]"`

**Type**: `dict`

**Example usage**:

```toml title="pyproject.toml"

[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 }
Expand Down
2 changes: 1 addition & 1 deletion uv.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58b5fd4

Please sign in to comment.