//python/uv:repositories.bzl
Repository rules and macros to set up uv in a WORKSPACE file.
- uv_register_toolchains(name='uv', manifests=None, version=None, configure=None, netrc=None, auth_patterns=None)
Create the
uvtoolchain repositories and register them in a WORKSPACE file.This is the WORKSPACE equivalent of the
uvmodule extension. It creates one download repository peruvversion and platform, and the toolchain hub repositorynamewith atoolchainfor each of them, which it registers as@{name}//:all;lockcan then be used, anduvcan be run directly viabazel run @{name}//:uv -- <args>. See the WORKSPACE setup guide for usage examples.Platforms without an archive in a manifest get no toolchain. The
configureentries are dicts with the attributes ofuv.configure; refer to theuv.configuredocumentation for how entries are applied.Note
A Python toolchain must be registered as well, e.g. via
python_register_toolchains, becauselockuses the Python exec tools toolchain to runuvwith a hermetic interpreter.Note
compatible_withandtarget_settingsare written into the hub repository’sBUILDfile as-is, so plain strings resolve relative to@{name}; passLabelobjects or@//-qualified strings for targets in your own repository.Added in version 2.5.0.
- Args:
the name of the toolchain hub repository. The download repositories are named
{name}_{version}_{platform}with.and-replaced by_.manifests– (dict[str,dict] |None) (default None)the download
urlsandsha256of the archives, keyed by version and then by platform ({version: {platform: {"urls": [...], "sha256": "..."}}}), as written todist_manifest.bzlbyuv_toolchains_manifest, which binds its own whenuv_register_toolchainsis loaded from there.version– (str|None) (default None)the
uvversion forconfigureentries that do not name one. Defaults to the first version ofmanifests, or to the version theuvextension uses by default when there are none.configure– (list[dict] |None) (default None)the entries to apply, each a dict with a subset of the
uv.configureattributes:version,platform,compatible_with,target_settings,urls,sha256,netrcandauth_patterns. Defaults to one empty entry per version ofmanifests, i.e. every version with the default platforms, or to a single entry forversion.netrc– (str|None) (default None)the default location of the
.netrcfile to use for authenticating the archive downloads.auth_patterns– (dict[str,str] |None) (default None)the default dict mapping host names to custom authorization patterns for the archive downloads, as understood by
http_archive.
- repo rule uv_toolchains_manifest(name, auth_patterns={}, base_url='https://github.com/astral-sh/uv/releases/download', manifest_filename='dist-manifest.json', netrc='', versions=['0.13.5'])
Fetch the release manifests of
uvversions in a WORKSPACE file.The repository downloads the manifest of every version in
versionsand writesdist_manifest.bzl, which has the download URLs and checksums of every archive in them asDIST_MANIFESTS, anduv_register_toolchainsbound to them; load that to create and register the toolchains:load("@rules_python//python/uv:repositories.bzl", "uv_toolchains_manifest") uv_toolchains_manifest( name = "uv_manifest", versions = ["0.13.5"], ) load("@uv_manifest//:dist_manifest.bzl", "uv_register_toolchains") uv_register_toolchains(name = "uv")
The manifests are read as-is: which platforms get a toolchain, and from which archives, is decided by
uv_register_toolchains. Versions released from different places can be fetched with one repository each and combined with themanifestsargument ofuv_register_toolchains.Added in version 2.5.0.
- Attributes:
A unique name for this repository.
mandatory
auth_patterns– (dict[str,str]) (default {})An optional dict mapping host names to custom authorization patterns.
If a URL’s host name is present in this dict the value will be used as a pattern when generating the authorization header for the http request. This enables the use of custom authorization schemes used in a lot of common cloud storage providers.
The pattern currently supports 2 tokens:
<login>and<password>, which are replaced with their equivalent value in the netrc file for the same host name. After formatting, the result is set as the value for theAuthorizationfield of the HTTP request.Example attribute and netrc for a http download to an oauth2 enabled API using a bearer token:
auth_patterns = { "storage.cloudprovider.com": "Bearer <password>" }netrc:
machine storage.cloudprovider.com password RANDOM-TOKENThe final HTTP request would have the following header:
Authorization: Bearer RANDOM-TOKEN
optional
base_url– (str) (default “https://github.com/astral-sh/uv/releases/download”)The base URL of the
uvreleases; the manifest of a version is downloaded from{base_url}/{version}/{manifest_filename}. Defaults to the GitHub releases ofuv.optional
manifest_filename– (str) (default “dist-manifest.json”)The release manifest file name.
optional
Location of the .netrc file to use for authentication
optional
versions– (list[str]) (default [“0.13.5”])The
uvversions to fetch the manifests of. Defaults to the version theuvextension uses by default.optional