Avoid duplicate [tool.uv] header in TOML examples (#8545)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / lint (push) Waiting to run
CI / cargo clippy | ubuntu (push) Blocked by required conditions
CI / cargo clippy | windows (push) Blocked by required conditions
CI / cargo dev generate-all (push) Blocked by required conditions
CI / cargo shear (push) Waiting to run
CI / cargo test | ubuntu (push) Blocked by required conditions
CI / cargo test | macos (push) Blocked by required conditions
CI / cargo test | windows (push) Blocked by required conditions
CI / check windows trampoline | aarch64 (push) Blocked by required conditions
CI / integration test | pypy on ubuntu (push) Blocked by required conditions
CI / check windows trampoline | i686 (push) Blocked by required conditions
CI / check windows trampoline | x86_64 (push) Blocked by required conditions
CI / test windows trampoline | i686 (push) Blocked by required conditions
CI / test windows trampoline | x86_64 (push) Blocked by required conditions
CI / typos (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / build binary | linux (push) Blocked by required conditions
CI / build binary | macos aarch64 (push) Blocked by required conditions
CI / build binary | macos x86_64 (push) Blocked by required conditions
CI / build binary | windows (push) Blocked by required conditions
CI / build binary | freebsd (push) Blocked by required conditions
CI / integration test | pypy on windows (push) Blocked by required conditions
CI / ecosystem test | prefecthq/prefect (push) Blocked by required conditions
CI / ecosystem test | pallets/flask (push) Blocked by required conditions
CI / integration test | conda on ubuntu (push) Blocked by required conditions
CI / integration test | free-threaded on linux (push) Blocked by required conditions
CI / integration test | free-threaded on windows (push) Blocked by required conditions
CI / integration test | graalpy on ubuntu (push) Blocked by required conditions
CI / integration test | graalpy on windows (push) Blocked by required conditions
CI / integration test | github actions (push) Blocked by required conditions
CI / integration test | determine publish changes (push) Blocked by required conditions
CI / integration test | uv publish (push) Blocked by required conditions
CI / check cache | ubuntu (push) Blocked by required conditions
CI / check cache | macos aarch64 (push) Blocked by required conditions
CI / check system | python on debian (push) Blocked by required conditions
CI / check system | python on fedora (push) Blocked by required conditions
CI / check system | python on ubuntu (push) Blocked by required conditions
CI / check system | python on opensuse (push) Blocked by required conditions
CI / check system | homebrew python on macos aarch64 (push) Blocked by required conditions
CI / check system | python on rocky linux 8 (push) Blocked by required conditions
CI / check system | python on rocky linux 9 (push) Blocked by required conditions
CI / check system | pypy on ubuntu (push) Blocked by required conditions
CI / check system | pyston (push) Blocked by required conditions
CI / check system | alpine (push) Blocked by required conditions
CI / check system | python on macos aarch64 (push) Blocked by required conditions
CI / check system | python on macos x86_64 (push) Blocked by required conditions
CI / check system | python3.10 on windows (push) Blocked by required conditions
CI / check system | python3.10 on windows x86 (push) Blocked by required conditions
CI / check system | python3.13 on windows (push) Blocked by required conditions
CI / check system | python3.12 via chocolatey (push) Blocked by required conditions
CI / check system | conda3.11 on windows (push) Blocked by required conditions
CI / check system | python3.9 via pyenv (push) Blocked by required conditions
CI / check system | python3.13 (push) Blocked by required conditions
CI / check system | conda3.11 on linux (push) Blocked by required conditions
CI / check system | conda3.8 on linux (push) Blocked by required conditions
CI / check system | conda3.11 on macos (push) Blocked by required conditions
CI / check system | conda3.8 on macos (push) Blocked by required conditions
CI / check system | conda3.8 on windows (push) Blocked by required conditions
CI / check system | amazonlinux (push) Blocked by required conditions
CI / check system | embedded python3.10 on windows (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

## Summary

For example, in:

```toml
[tool.uv]
[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu121"
```

We can just omit `[tool.uv]`.
This commit is contained in:
Charlie Marsh 2024-10-24 17:10:01 -04:00 committed by GitHub
parent ec71fb1f75
commit 99a87464eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 51 deletions

View file

@ -268,7 +268,12 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[S
} => { } => {
output.push_str(&format_code( output.push_str(&format_code(
"pyproject.toml", "pyproject.toml",
&format_header(field.scope, parents, ConfigurationFile::PyprojectToml), &format_header(
field.scope,
field.example,
parents,
ConfigurationFile::PyprojectToml,
),
field.example, field.example,
)); ));
} }
@ -278,12 +283,22 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[S
} => { } => {
output.push_str(&format_tab( output.push_str(&format_tab(
"pyproject.toml", "pyproject.toml",
&format_header(field.scope, parents, ConfigurationFile::PyprojectToml), &format_header(
field.scope,
field.example,
parents,
ConfigurationFile::PyprojectToml,
),
field.example, field.example,
)); ));
output.push_str(&format_tab( output.push_str(&format_tab(
"uv.toml", "uv.toml",
&format_header(field.scope, parents, ConfigurationFile::UvToml), &format_header(
field.scope,
field.example,
parents,
ConfigurationFile::UvToml,
),
field.example, field.example,
)); ));
} }
@ -293,12 +308,20 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, parents: &[S
} }
fn format_tab(tab_name: &str, header: &str, content: &str) -> String { fn format_tab(tab_name: &str, header: &str, content: &str) -> String {
if header.is_empty() {
format!(
"=== \"{}\"\n\n ```toml\n{}\n ```\n",
tab_name,
textwrap::indent(content, " ")
)
} else {
format!( format!(
"=== \"{}\"\n\n ```toml\n {}\n{}\n ```\n", "=== \"{}\"\n\n ```toml\n {}\n{}\n ```\n",
tab_name, tab_name,
header, header,
textwrap::indent(content, " ") textwrap::indent(content, " ")
) )
}
} }
fn format_code(file_name: &str, header: &str, content: &str) -> String { fn format_code(file_name: &str, header: &str, content: &str) -> String {
@ -308,7 +331,12 @@ fn format_code(file_name: &str, header: &str, content: &str) -> String {
/// Format the TOML header for the example usage for a given option. /// Format the TOML header for the example usage for a given option.
/// ///
/// For example: `[tool.uv.pip]`. /// For example: `[tool.uv.pip]`.
fn format_header(scope: Option<&str>, parents: &[Set], configuration: ConfigurationFile) -> String { fn format_header(
scope: Option<&str>,
example: &str,
parents: &[Set],
configuration: ConfigurationFile,
) -> String {
let tool_parent = match configuration { let tool_parent = match configuration {
ConfigurationFile::PyprojectToml => Some("tool.uv"), ConfigurationFile::PyprojectToml => Some("tool.uv"),
ConfigurationFile::UvToml => None, ConfigurationFile::UvToml => None,
@ -320,6 +348,15 @@ fn format_header(scope: Option<&str>, parents: &[Set], configuration: Configurat
.chain(scope) .chain(scope)
.join("."); .join(".");
// Ex) `[[tool.uv.index]]`
if example.starts_with(&format!("[[{header}")) {
return String::new();
}
// Ex) `[tool.uv.sources]`
if example.starts_with(&format!("[{header}")) {
return String::new();
}
if header.is_empty() { if header.is_empty() {
String::new() String::new()
} else { } else {

View file

@ -110,7 +110,7 @@ PyPI default index.
**Example usage**: **Example usage**:
```toml title="pyproject.toml" ```toml title="pyproject.toml"
[tool.uv]
[[tool.uv.index]] [[tool.uv.index]]
name = "pytorch" name = "pytorch"
url = "https://download.pytorch.org/whl/cu121" url = "https://download.pytorch.org/whl/cu121"
@ -272,7 +272,6 @@ bypasses SSL verification and could expose you to MITM attacks.
=== "uv.toml" === "uv.toml"
```toml ```toml
allow-insecure-host = ["localhost:8080"] allow-insecure-host = ["localhost:8080"]
``` ```
@ -300,7 +299,6 @@ Linux, and `%LOCALAPPDATA%\uv\cache` on Windows.
=== "uv.toml" === "uv.toml"
```toml ```toml
cache-dir = "./.uv_cache" cache-dir = "./.uv_cache"
``` ```
@ -353,7 +351,6 @@ globs are interpreted as relative to the project directory.
=== "uv.toml" === "uv.toml"
```toml ```toml
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = { commit = true }] cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = { commit = true }]
``` ```
@ -387,7 +384,6 @@ ignore errors.
=== "uv.toml" === "uv.toml"
```toml ```toml
compile-bytecode = true compile-bytecode = true
``` ```
@ -415,7 +411,6 @@ Defaults to the number of available CPU cores.
=== "uv.toml" === "uv.toml"
```toml ```toml
concurrent-builds = 4 concurrent-builds = 4
``` ```
@ -441,7 +436,6 @@ time.
=== "uv.toml" === "uv.toml"
```toml ```toml
concurrent-downloads = 4 concurrent-downloads = 4
``` ```
@ -468,7 +462,6 @@ Defaults to the number of available CPU cores.
=== "uv.toml" === "uv.toml"
```toml ```toml
concurrent-installs = 4 concurrent-installs = 4
``` ```
@ -494,7 +487,6 @@ specified as `KEY=VALUE` pairs.
=== "uv.toml" === "uv.toml"
```toml ```toml
config-settings = { editable_mode = "compat" } config-settings = { editable_mode = "compat" }
``` ```
@ -533,7 +525,6 @@ standard, though only the following fields are respected:
=== "uv.toml" === "uv.toml"
```toml ```toml
dependency-metadata = [ dependency-metadata = [
{ name = "flask", version = "1.0.0", requires-dist = ["werkzeug"], requires-python = ">=3.6" }, { name = "flask", version = "1.0.0", requires-dist = ["werkzeug"], requires-python = ">=3.6" },
] ]
@ -564,7 +555,6 @@ system's configured time zone.
=== "uv.toml" === "uv.toml"
```toml ```toml
exclude-newer = "2006-12-02" exclude-newer = "2006-12-02"
``` ```
@ -601,7 +591,6 @@ To control uv's resolution strategy when multiple indexes are present, see
=== "uv.toml" === "uv.toml"
```toml ```toml
extra-index-url = ["https://download.pytorch.org/whl/cpu"] extra-index-url = ["https://download.pytorch.org/whl/cpu"]
``` ```
@ -633,7 +622,6 @@ formats described above.
=== "uv.toml" === "uv.toml"
```toml ```toml
find-links = ["https://download.pytorch.org/whl/torch_stable.html"] find-links = ["https://download.pytorch.org/whl/torch_stable.html"]
``` ```
@ -678,7 +666,6 @@ PyPI default index.
=== "pyproject.toml" === "pyproject.toml"
```toml ```toml
[tool.uv]
[[tool.uv.index]] [[tool.uv.index]]
name = "pytorch" name = "pytorch"
url = "https://download.pytorch.org/whl/cu121" url = "https://download.pytorch.org/whl/cu121"
@ -686,7 +673,6 @@ PyPI default index.
=== "uv.toml" === "uv.toml"
```toml ```toml
[[tool.uv.index]] [[tool.uv.index]]
name = "pytorch" name = "pytorch"
url = "https://download.pytorch.org/whl/cu121" url = "https://download.pytorch.org/whl/cu121"
@ -722,7 +708,6 @@ same name to an alternate index.
=== "uv.toml" === "uv.toml"
```toml ```toml
index-strategy = "unsafe-best-match" index-strategy = "unsafe-best-match"
``` ```
@ -755,7 +740,6 @@ The index provided by this setting is given lower priority than any indexes spec
=== "uv.toml" === "uv.toml"
```toml ```toml
index-url = "https://test.pypi.org/simple" index-url = "https://test.pypi.org/simple"
``` ```
@ -783,7 +767,6 @@ use the `keyring` CLI to handle authentication.
=== "uv.toml" === "uv.toml"
```toml ```toml
keyring-provider = "subprocess" keyring-provider = "subprocess"
``` ```
@ -816,7 +799,6 @@ Windows.
=== "uv.toml" === "uv.toml"
```toml ```toml
link-mode = "copy" link-mode = "copy"
``` ```
@ -849,7 +831,6 @@ included in your system's certificate store.
=== "uv.toml" === "uv.toml"
```toml ```toml
native-tls = true native-tls = true
``` ```
@ -877,7 +858,6 @@ pre-built wheels to extract package metadata, if available.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-binary = true no-binary = true
``` ```
@ -902,7 +882,6 @@ Don't install pre-built wheels for a specific package.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-binary-package = ["ruff"] no-binary-package = ["ruff"]
``` ```
@ -931,7 +910,6 @@ distributions will exit with an error.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-build = true no-build = true
``` ```
@ -959,7 +937,6 @@ are already installed.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-build-isolation = true no-build-isolation = true
``` ```
@ -987,7 +964,6 @@ are already installed.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-build-isolation-package = ["package1", "package2"] no-build-isolation-package = ["package1", "package2"]
``` ```
@ -1012,7 +988,6 @@ Don't build source distributions for a specific package.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-build-package = ["ruff"] no-build-package = ["ruff"]
``` ```
@ -1038,7 +1013,6 @@ duration of the operation.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-cache = true no-cache = true
``` ```
@ -1064,7 +1038,6 @@ those provided via `--find-links`.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-index = true no-index = true
``` ```
@ -1091,7 +1064,6 @@ sources.
=== "uv.toml" === "uv.toml"
```toml ```toml
no-sources = true no-sources = true
``` ```
@ -1116,7 +1088,6 @@ Disable network access, relying only on locally cached data and locally availabl
=== "uv.toml" === "uv.toml"
```toml ```toml
offline = true offline = true
``` ```
@ -1151,7 +1122,6 @@ declared specifiers (`if-necessary-or-explicit`).
=== "uv.toml" === "uv.toml"
```toml ```toml
prerelease = "allow" prerelease = "allow"
``` ```
@ -1176,7 +1146,6 @@ Whether to enable experimental, preview features.
=== "uv.toml" === "uv.toml"
```toml ```toml
preview = true preview = true
``` ```
@ -1202,7 +1171,6 @@ The URL for publishing packages to the Python package index (by default:
=== "uv.toml" === "uv.toml"
```toml ```toml
publish-url = "https://test.pypi.org/legacy/" publish-url = "https://test.pypi.org/legacy/"
``` ```
@ -1231,7 +1199,6 @@ Whether to allow Python downloads.
=== "uv.toml" === "uv.toml"
```toml ```toml
python-downloads = "manual" python-downloads = "manual"
``` ```
@ -1262,7 +1229,6 @@ those that are downloaded and installed by uv.
=== "uv.toml" === "uv.toml"
```toml ```toml
python-preference = "managed" python-preference = "managed"
``` ```
@ -1287,7 +1253,6 @@ Reinstall all packages, regardless of whether they're already installed. Implies
=== "uv.toml" === "uv.toml"
```toml ```toml
reinstall = true reinstall = true
``` ```
@ -1313,7 +1278,6 @@ Reinstall a specific package, regardless of whether it's already installed. Impl
=== "uv.toml" === "uv.toml"
```toml ```toml
reinstall-package = ["ruff"] reinstall-package = ["ruff"]
``` ```
@ -1345,7 +1309,6 @@ By default, uv will use the latest compatible version of each package (`highest`
=== "uv.toml" === "uv.toml"
```toml ```toml
resolution = "lowest-direct" resolution = "lowest-direct"
``` ```
@ -1374,7 +1337,6 @@ from a fork).
=== "uv.toml" === "uv.toml"
```toml ```toml
trusted-publishing = "always" trusted-publishing = "always"
``` ```
@ -1399,7 +1361,6 @@ Allow package upgrades, ignoring pinned versions in any existing output file.
=== "uv.toml" === "uv.toml"
```toml ```toml
upgrade = true upgrade = true
``` ```
@ -1427,7 +1388,6 @@ Accepts both standalone package names (`ruff`) and version specifiers (`ruff<0.5
=== "uv.toml" === "uv.toml"
```toml ```toml
upgrade-package = ["ruff"] upgrade-package = ["ruff"]
``` ```