uv/scripts/generate-crate-readmes.py
Zanie Blue 7b8240dca9
Some checks failed
zizmor / Run zizmor (push) Has been cancelled
CI / Determine changes (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / cargo shear (push) Has been cancelled
CI / typos (push) Has been cancelled
CI / mkdocs (push) Has been cancelled
CI / cargo clippy | ubuntu (push) Has been cancelled
CI / cargo clippy | windows (push) Has been cancelled
CI / cargo publish dry-run (push) Has been cancelled
CI / cargo dev generate-all (push) Has been cancelled
CI / cargo test | ubuntu (push) Has been cancelled
CI / cargo test | macos (push) Has been cancelled
CI / cargo test | windows (push) Has been cancelled
CI / check windows trampoline | aarch64 (push) Has been cancelled
CI / check windows trampoline | i686 (push) Has been cancelled
CI / check windows trampoline | x86_64 (push) Has been cancelled
CI / integration test | deadsnakes python3.9 on ubuntu (push) Has been cancelled
CI / test windows trampoline | aarch64 (push) Has been cancelled
CI / test windows trampoline | i686 (push) Has been cancelled
CI / test windows trampoline | x86_64 (push) Has been cancelled
CI / build binary | linux libc (push) Has been cancelled
CI / build binary | linux aarch64 (push) Has been cancelled
CI / build binary | linux musl (push) Has been cancelled
CI / build binary | macos aarch64 (push) Has been cancelled
CI / build binary | macos x86_64 (push) Has been cancelled
CI / build binary | windows x86_64 (push) Has been cancelled
CI / build binary | windows aarch64 (push) Has been cancelled
CI / build binary | msrv (push) Has been cancelled
CI / build binary | freebsd (push) Has been cancelled
CI / ecosystem test | pydantic/pydantic-core (push) Has been cancelled
CI / ecosystem test | prefecthq/prefect (push) Has been cancelled
CI / ecosystem test | pallets/flask (push) Has been cancelled
CI / smoke test | linux (push) Has been cancelled
CI / smoke test | linux aarch64 (push) Has been cancelled
CI / check system | alpine (push) Has been cancelled
CI / smoke test | macos (push) Has been cancelled
CI / smoke test | windows x86_64 (push) Has been cancelled
CI / smoke test | windows aarch64 (push) Has been cancelled
CI / integration test | activate nushell venv (push) Has been cancelled
CI / integration test | conda on ubuntu (push) Has been cancelled
CI / integration test | free-threaded on windows (push) Has been cancelled
CI / integration test | aarch64 windows implicit (push) Has been cancelled
CI / integration test | aarch64 windows explicit (push) Has been cancelled
CI / integration test | windows python install manager (push) Has been cancelled
CI / integration test | pypy on ubuntu (push) Has been cancelled
CI / integration test | pypy on windows (push) Has been cancelled
CI / integration test | graalpy on ubuntu (push) Has been cancelled
CI / integration test | graalpy on windows (push) Has been cancelled
CI / integration test | pyodide on ubuntu (push) Has been cancelled
CI / integration test | github actions (push) Has been cancelled
CI / integration test | free-threaded python on github actions (push) Has been cancelled
CI / integration test | pyenv on wsl x86-64 (push) Has been cancelled
CI / integration test | determine publish changes (push) Has been cancelled
CI / integration test | registries (push) Has been cancelled
CI / integration test | uv publish (push) Has been cancelled
CI / integration test | uv_build (push) Has been cancelled
CI / check cache | ubuntu (push) Has been cancelled
CI / check cache | macos aarch64 (push) Has been cancelled
CI / check system | python on debian (push) Has been cancelled
CI / check system | python on fedora (push) Has been cancelled
CI / check system | python on ubuntu (push) Has been cancelled
CI / check system | python on rocky linux 10 (push) Has been cancelled
CI / check system | python on rocky linux 8 (push) Has been cancelled
CI / check system | python on rocky linux 9 (push) Has been cancelled
CI / check system | graalpy on ubuntu (push) Has been cancelled
CI / check system | pypy on ubuntu (push) Has been cancelled
CI / check system | pyston (push) Has been cancelled
CI / check system | python on macos aarch64 (push) Has been cancelled
CI / check system | homebrew python on macos aarch64 (push) Has been cancelled
CI / check system | x86-64 python on macos aarch64 (push) Has been cancelled
CI / check system | python on macos x86-64 (push) Has been cancelled
CI / check system | python3.10 on windows x86-64 (push) Has been cancelled
CI / check system | python3.10 on windows x86 (push) Has been cancelled
CI / check system | python3.13 on windows x86-64 (push) Has been cancelled
CI / check system | x86-64 python3.13 on windows aarch64 (push) Has been cancelled
CI / check system | aarch64 python3.13 on windows aarch64 (push) Has been cancelled
CI / check system | windows registry (push) Has been cancelled
CI / check system | python3.12 via chocolatey (push) Has been cancelled
CI / check system | python3.9 via pyenv (push) Has been cancelled
CI / check system | python3.13 (push) Has been cancelled
CI / check system | conda3.11 on macos aarch64 (push) Has been cancelled
CI / check system | conda3.8 on macos aarch64 (push) Has been cancelled
CI / check system | conda3.11 on linux x86-64 (push) Has been cancelled
CI / check system | conda3.8 on linux x86-64 (push) Has been cancelled
CI / check system | conda3.11 on windows x86-64 (push) Has been cancelled
CI / check system | conda3.8 on windows x86-64 (push) Has been cancelled
CI / check system | amazonlinux (push) Has been cancelled
CI / check system | embedded python3.10 on windows x86-64 (push) Has been cancelled
CI / benchmarks | walltime aarch64 linux (push) Has been cancelled
CI / benchmarks | instrumented (push) Has been cancelled
Generate a README for crate members too (#16812)
We skip members with existing READMEs for now.

Follows #16809 and #16811
2025-11-21 15:44:05 -06:00

123 lines
3.6 KiB
Python

# /// script
# requires-python = ">=3.13"
# dependencies = []
# ///
import json
import pathlib
import subprocess
GENERATED_HEADER = "<!-- This file is generated. DO NOT EDIT -->"
UV_TEMPLATE = """
{GENERATED_HEADER}
# uv
uv is a Python package and project manager.
See the [documentation](https://docs.astral.sh/uv/) or [repository](https://github.com/astral-sh/uv)
for more information.
This crate is the entry point to the uv command-line interface. The Rust API exposed here is not
considered public interface.
The following uv workspace members are also available:
{WORKSPACE_MEMBERS}
uv's workspace members are considered internal and will have frequent breaking changes.
See uv's [crate versioning policy](https://docs.astral.sh/uv/reference/policies/versioning/#crate-versioning) for details on versioning.
"""
MEMBER_TEMPLATE = """
{GENERATED_HEADER}
# {name}
This crate is an internal component of [uv](https://crates.io/uv). The Rust API exposed here is
unstable and will have frequent breaking changes.
See uv's [crate versioning
policy](https://docs.astral.sh/uv/reference/policies/versioning/#crate-versioning) for details on
versioning.
"""
def main() -> None:
result = subprocess.run(
["cargo", "metadata", "--format-version", "1"],
capture_output=True,
text=True,
check=True,
)
content = json.loads(result.stdout)
packages = {package["id"]: package for package in content["packages"]}
workspace_root = pathlib.Path(content["workspace_root"])
readme_path = workspace_root / "crates" / "uv" / "README.md"
workspace_members = []
for workspace_member in content["workspace_members"]:
name = packages[workspace_member]["name"]
if name != "uv":
workspace_members.append(name)
workspace_members.sort()
members_list = "\n".join(
f"- [{name}](https://crates.io/crates/{name})" for name in workspace_members
)
# Generate README for the main uv crate
readme_content = UV_TEMPLATE.format(
GENERATED_HEADER=GENERATED_HEADER, WORKSPACE_MEMBERS=members_list
)
readme_path.write_text(readme_content)
# Track all generated README paths for formatting at the end
generated_paths = [readme_path]
# Generate READMEs for all workspace members
for workspace_member in content["workspace_members"]:
package = packages[workspace_member]
name = package["name"]
# Skip the main uv crate (already handled above)
if name == "uv":
continue
# Determine the README path for this crate
manifest_path = pathlib.Path(package["manifest_path"])
crate_dir = manifest_path.parent
member_readme_path = crate_dir / "README.md"
# Check if README already exists
if member_readme_path.exists():
existing_content = member_readme_path.read_text()
# Skip if it doesn't have the generated header
if not existing_content.startswith(GENERATED_HEADER):
print(f"Skipping {name}: existing README without generated header")
continue
# Generate the README content
member_readme_content = MEMBER_TEMPLATE.format(
GENERATED_HEADER=GENERATED_HEADER, name=name
)
member_readme_path.write_text(member_readme_content)
generated_paths.append(member_readme_path)
print(f"Generated README for {name}")
# Format all generated READMEs once at the end
subprocess.run(
["npx", "prettier", "--write", "--prose-wrap", "always"]
+ [str(path) for path in generated_paths],
check=True,
)
if __name__ == "__main__":
main()