From 44a6dbfa53c8cf833a75c92ca0fce25c5a2be110 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Sat, 3 Aug 2024 08:41:33 -0500 Subject: [PATCH] Improvements to the documentation (#5718) --- CONTRIBUTING.md | 4 +- STYLE.md | 3 +- docs/concepts/projects.md | 4 +- docs/concepts/python-versions.md | 45 ++++++----- docs/features.md | 7 +- docs/first-steps.md | 10 ++- docs/guides/install-python.md | 46 ++++++++++-- .../guides/integration/alternative-indexes.md | 21 +++--- docs/guides/integration/docker.md | 4 +- docs/guides/projects.md | 10 ++- docs/guides/scripts.md | 40 +++++++--- docs/guides/tools.md | 4 +- docs/index.md | 45 ++++++----- docs/installation.md | 62 ++++++++-------- docs/pip/compile.md | 48 ++++++------ docs/pip/environments.md | 35 ++++----- docs/pip/inspection.md | 20 ++--- docs/pip/packages.md | 74 +++++++++---------- mkdocs.template.yml | 2 +- 19 files changed, 275 insertions(+), 209 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c14969255..a38ce0fd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,8 +78,8 @@ system ["nvidia-pyindex" on PyPI](https://pypi.org/project/nvidia-pyindex/)), which can even occur when just resolving requirements. To prevent this, there's a Docker container you can run commands in: -```bash -docker buildx build -t uv-builder -f builder.dockerfile --load . +```console +$ docker buildx build -t uv-builder -f builder.dockerfile --load . # Build for musl to avoid glibc errors, might not be required with your OS version cargo build --target x86_64-unknown-linux-musl --profile profiling docker run --rm -it -v $(pwd):/app uv-builder /app/target/x86_64-unknown-linux-musl/profiling/uv-dev resolve-many --cache-dir /app/cache-docker /app/scripts/popular_packages/pypi_10k_most_dependents.txt diff --git a/STYLE.md b/STYLE.md index a87eb1e94..259f70712 100644 --- a/STYLE.md +++ b/STYLE.md @@ -84,7 +84,8 @@ The documentation is divided into: 1. All code blocks should have a language marker. 1. When using `console` syntax, use `$` to indicate commands — everything else is output. -1. Do not use the `bash` syntax when displaying command output. +1. Never use the `bash` syntax when displaying command output. +1. Prefer `console` with `$` prefixed commands over `bash`. 1. Command output should rarely be included — it's hard to keep up to date. 1. Use `title` for example files, e.g., `pyproject.toml`, `Dockerfile`, or `example.py`. diff --git a/docs/concepts/projects.md b/docs/concepts/projects.md index f350fca6c..f75b2ffea 100644 --- a/docs/concepts/projects.md +++ b/docs/concepts/projects.md @@ -152,10 +152,10 @@ command. The given command can be provided by the project environment or exist outside of it, e.g.: ```console -# Presuming the project provides `example-cli` +$ # Presuming the project provides `example-cli` $ uv run example-cli foo -# Running a `bash` script that requires the project to be available +$ # Running a `bash` script that requires the project to be available $ uv run bash scripts/foo.sh ``` diff --git a/docs/concepts/python-versions.md b/docs/concepts/python-versions.md index 8a77ae43b..a2dc21ed4 100644 --- a/docs/concepts/python-versions.md +++ b/docs/concepts/python-versions.md @@ -22,8 +22,8 @@ installations and all other Python installations as _system_ Python installation A specific Python version can be requested with the `--python` flag in most uv commands. For example, when creating a virtual environment: -```bash -uv venv --python 3.11.6 +```console +$ uv venv --python 3.11.6 ``` uv will ensure that Python 3.11.6 is available — downloading and installing it if necessary — then @@ -60,28 +60,37 @@ uv bundles a list of downloadable CPython and PyPy distributions for macOS, Linu To install a Python version at a specific version: -```bash -uv python install 3.12.3 +```console +$ uv python install 3.12.3 ``` To install the latest patch version: -```bash -uv python install 3.12 +```console +$ uv python install 3.12 ``` To install a version that satisfies constraints: -```bash -uv python install '>=3.8,<3.10' +```console +$ uv python install '>=3.8,<3.10' ``` To install multiple versions: -```bash -uv python install 3.9 3.10 3.11 +```console +$ uv python install 3.9 3.10 3.11 ``` +To install a specific implementation: + +```console +$ uv python install pypy +``` + +All of the [Python version request](#requesting-a-version) formats are supported except those that +are used for requesting local interpreters such as a file path. + ## Project Python versions By default `uv python install` will verify that a managed Python version is installed or install the @@ -101,28 +110,28 @@ invocations. To list installed and available Python versions: -```bash -uv python list +```console +$ uv python list ``` By default, downloads for other platforms and old patch versions are hidden. To view all versions: -```bash -uv python list --all-versions +```console +$ uv python list --all-versions ``` To view Python versions for other platforms: -```bash -uv python list --all-platforms +```console +$ uv python list --all-platforms ``` To exclude downloads and only show installed Python versions: -```bash -uv python list --only-installed +```console +$ uv python list --only-installed ``` ## Discovery of Python versions diff --git a/docs/features.md b/docs/features.md index 38f87da50..586d9031e 100644 --- a/docs/features.md +++ b/docs/features.md @@ -1,10 +1,9 @@ # Features -uv supports the full Python development experience — from installing Python and hacking on simple +uv provides essential features for Python development — from installing Python and hacking on simple scripts to working on large projects that support multiple Python versions and platforms. -uv's commands can be broken down into sections of discrete features, which can be used -independently. +uv's interface can be broken down into sections, which can be used independently or together. ## Python versions @@ -87,7 +86,7 @@ See the documentation on [locking environments](./pip/compile.md) for details. These commands do not exactly implement the interfaces and behavior of the tools they are based on. The further you stray from common workflows, the more likely you are to encounter differences. Consult the [pip-compatibility guide](./pip/compatibility.md) for details. -## Internal +## Utility Managing and inspecting uv's state, such as the cache, storage directories, or performing a self-update: diff --git a/docs/first-steps.md b/docs/first-steps.md index cda5cc9bb..ef13bf478 100644 --- a/docs/first-steps.md +++ b/docs/first-steps.md @@ -2,11 +2,16 @@ uv only provides a command-line interface and must be used from a terminal. -After [installing uv](./installation.md), you can check that uv is installed by running the `uv` +After [installing uv](./installation.md), you can check that uv is available by running the `uv` command: ```console $ uv +An extremely fast Python package manager. + +Usage: uv [OPTIONS] + +... ``` You should see a help menu listing the available commands. @@ -63,5 +68,4 @@ $ uv pip --version # Can be used with a subcommand ## Next steps Now that you've confirmed uv is installed and know how to get help, check out an -[overview of features](./features.md) or jump straight into the [guides](./guides/index.md) to start -using uv. +[overview of features](./features.md) or jump to the [guides](./guides/index.md) to start using uv. diff --git a/docs/guides/install-python.md b/docs/guides/install-python.md index 520d323e4..639cec2cb 100644 --- a/docs/guides/install-python.md +++ b/docs/guides/install-python.md @@ -8,14 +8,18 @@ also install and manage Python versions for you. uv will [automatically fetch Python versions](#automatic-python-downloads) as needed — you don't need to install Python to get started. + + +## Getting started + To install the latest Python version: ```console $ uv python install ``` -This will install a uv managed Python version even if there is already a Python installation on your -system. +This will install a uv-managed Python version even if there is already a Python installation on your +system. If you've previously installed Python with uv, a new version will not be installed. !!! note @@ -35,6 +39,13 @@ To prevent uv from managing Python system-wide, provide the `--no-shim` option d Once Python is installed, it will be used by `uv` commands automatically. +!!! important + + When Python is installed by uv, it will not be available globally (i.e. via the `python` command). + Support for this feature is planned for a future release. In the meantime, use + [`uv run`](../guides/scripts.md#using-different-python-versions) or + [create and activate a virtual environment](../pip/environments.md) to use `python` directly. + ## Installing a specific version To install a specific Python version: @@ -43,6 +54,18 @@ To install a specific Python version: $ uv python install 3.12 ``` +To install multiple Python versions: + +```console +$ uv python install 3.11 3.12 +``` + +To install an alternative Python implementation, e.g. PyPy: + +``` +$ uv python install pypy@3.12 +``` + See the [`python install`](../concepts/python-versions.md#installing-a-python-version) documentation for more details. @@ -77,17 +100,28 @@ version if Python is not found: $ uv venv ``` +!!! tip + + Automatic Python downloads can be [easily disabled](../concepts/python-versions.md#disabling-automatic-python-downloads) if you want more control over when Python is downloaded. + ## Using an existing Python installation -uv will also use an existing Python installation if already present on your system. There is no -configuration necessary for this behavior: uv will use the system Python if it satisfies the -requirements of the command invocation. See the -[Python discovery](../concepts/python-versions.md#discovery-order) documentation for details. +uv will use existing Python installations if present on your system. There is no configuration +necessary for this behavior: uv will use the system Python if it satisfies the requirements of the +command invocation. See the [Python discovery](../concepts/python-versions.md#discovery-order) +documentation for details. To force uv to use the system Python, provide the `--python-preference only-system` option. See the [Python version preference](../concepts/python-versions.md#adjusting-python-version-preferences) documentation for more details. + +## Next steps + +To learn more about `uv python`, see the [Python version concept](../concepts/python-versions.md) +page and the [command reference](../reference/cli.md#uv-python). + +Or, read on to learn how to [run scripts](./scripts.md) and invoke Python with uv. diff --git a/docs/guides/integration/alternative-indexes.md b/docs/guides/integration/alternative-indexes.md index d30b6cf13..6526111bd 100644 --- a/docs/guides/integration/alternative-indexes.md +++ b/docs/guides/integration/alternative-indexes.md @@ -19,9 +19,10 @@ If there is a PAT available (eg credentials can be provided via the "Basic" HTTP authentication scheme. Include the PAT in the password field of the URL. A username must be included as well, but can be any string. -```bash -# With the token stored in the `ADO_PAT` environment variable -export UV_EXTRA_INDEX_URL=https://dummy:$ADO_PAT@pkgs.dev.azure.com/{organisation}/{project}/_packaging/{feedName}/pypi/simple/ +For example, with the token stored in the `$ADO_PAT` environment variable, set the index URL with: + +```console +$ export UV_EXTRA_INDEX_URL=https://dummy:$ADO_PAT@pkgs.dev.azure.com/{organisation}/{project}/_packaging/{feedName}/pypi/simple/ ``` ### Using `keyring` @@ -44,15 +45,15 @@ The `keyring` executable must be in the `PATH`, i.e., installed globally or in t environment. The `keyring` CLI requires a username in the URL, so the index URL must include the default username `VssSessionToken`. -```bash -# Pre-install keyring and the Artifacts plugin from the public PyPI -uv tool install keyring --with artifacts-keyring +```console +$ # Pre-install keyring and the Artifacts plugin from the public PyPI +$ uv tool install keyring --with artifacts-keyring -# Enable keyring authentication -export UV_KEYRING_PROVIDER=subprocess +$ # Enable keyring authentication +$ export UV_KEYRING_PROVIDER=subprocess -# Configure the index URL with the username -export UV_EXTRA_INDEX_URL=https://VssSessionToken@pkgs.dev.azure.com/{organisation}/{project}/_packaging/{feedName}/pypi/simple/ +$ # Configure the index URL with the username +$ export UV_EXTRA_INDEX_URL=https://VssSessionToken@pkgs.dev.azure.com/{organisation}/{project}/_packaging/{feedName}/pypi/simple/ ``` ## Other indexes diff --git a/docs/guides/integration/docker.md b/docs/guides/integration/docker.md index e821f830f..53560fb2a 100644 --- a/docs/guides/integration/docker.md +++ b/docs/guides/integration/docker.md @@ -5,8 +5,8 @@ A Docker image is published with a built version of uv available. To run a uv command in a container: -```bash -docker run ghcr.io/astral-sh/uv --help +```console +$ docker run ghcr.io/astral-sh/uv --help ``` ## Installing uv diff --git a/docs/guides/projects.md b/docs/guides/projects.md index dad7995ad..6422815ba 100644 --- a/docs/guides/projects.md +++ b/docs/guides/projects.md @@ -106,10 +106,10 @@ $ uv add requests You can also specify version constraints or alternative sources: ```console -# Specify a version constraint +$ # Specify a version constraint $ uv add 'requests==2.31.0' -# Add a git dependency +$ # Add a git dependency $ uv add requests --git https://github.com/psf/requests ``` @@ -166,5 +166,7 @@ See the documentation on [running commands](../concepts/projects.md#running-comm ## Next steps -See the [projects concept](../concepts/projects.md) documentation for more details about working -with projects. +To learn more about working on projects with uv, see the [Projects concept](../concepts/projects.md) +page and the [command reference](../reference/cli.md#uv). + +Or, read on to learn how to [run and install tools](./tools.md) with uv. diff --git a/docs/guides/scripts.md b/docs/guides/scripts.md index ba084ff03..e7a595033 100644 --- a/docs/guides/scripts.md +++ b/docs/guides/scripts.md @@ -1,8 +1,15 @@ # Running scripts A Python script is a file intended for standalone execution, e.g., with `python