//python/uv:uv.bzl

EXPERIMENTAL: This is experimental and may be removed without notice.

The uv toolchain extension.

module ext uv

A module extension for working with uv.

Basic usage:

uv = use_extension(
    "@rules_python//python/uv:uv.bzl",
    "uv",
    # Use `dev_dependency` so that the toolchains are not defined pulled when
    # your module is used elsewhere.
    dev_dependency = True,
)
uv.configure(version = "0.5.24")

Since this is only for locking the requirements files, it should be always marked as a dev_dependency.

uv.configure(auth_patterns={}, base_url='', compatible_with=[], manifest_filename='dist-manifest.json', netrc='', platform='', sha256='', target_settings=[], urls=[], version='')

Build the uv toolchain configuration by appending the provided configuration. The information is appended to the version configuration that is specified by version attribute, or if the version is unspecified, the version of the last uv.configure call in the current module, or the version from the defaults is used.

Complex configuration example:

# Configure the base_url for the default version.
uv.configure(base_url = "my_mirror")

# Add an extra platform that can be used with your version.
uv.configure(
    platform = "extra-platform",
    target_settings = ["//my_config_setting_label"],
    compatible_with = ["@platforms//os:exotic"],
)

# Add an extra platform that can be used with your version.
uv.configure(
    platform = "patched-binary",
    target_settings = ["//my_super_config_setting"],
    urls = ["https://example.zip"],
    sha256 = "deadbeef",
)
Attributes:
  • 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 the Authorization field 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-TOKEN
    

    The final HTTP request would have the following header:

    Authorization: Bearer RANDOM-TOKEN
    

    optional

  • base_url(str) (default “”)

    Base URL to download metadata about the binaries and the binaries themselves.

    optional

  • compatible_with(list[label]) (default [])

    The compatible with constraint values for toolchain resolution.

    optional

  • manifest_filename(str) (default “dist-manifest.json”)

    The distribution manifest filename to use for the metadata fetching from GH. The defaults for this are set in rules_python MODULE.bazel file that one can override for a specific version.

    optional

  • netrc(str) (default “”)

    Location of the .netrc file to use for authentication

    optional

  • platform(str) (default “”)

    The platform string used in the UV repository to denote the platform triple.

    optional

  • sha256(str) (default “”)

    The sha256 of the downloaded artifact if the urls is specified.

    optional

  • target_settings(list[label]) (default [])

    The target_settings to add to platform definitions that then get used in toolchain definitions.

    optional

  • urls(list[str]) (default [])

    The urls to download the binary from. If this is used, base_url and manifest_filename are ignored for the given version.

    If the urls are specified, they need to be specified for all of the platforms for a particular version.

    optional

  • version(str) (default “”)

    The version of uv to configure the sources for. If this is not specified it will be the last version used in the module or the default version set by rules_python.

    optional

uv.default(auth_patterns={}, base_url='', compatible_with=[], manifest_filename='dist-manifest.json', netrc='', platform='', target_settings=[], version='')

Set the uv configuration defaults.

Attributes:
  • 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 the Authorization field 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-TOKEN
    

    The final HTTP request would have the following header:

    Authorization: Bearer RANDOM-TOKEN
    

    optional

  • base_url(str) (default “”)

    Base URL to download metadata about the binaries and the binaries themselves.

    optional

  • compatible_with(list[label]) (default [])

    The compatible with constraint values for toolchain resolution.

    optional

  • manifest_filename(str) (default “dist-manifest.json”)

    The distribution manifest filename to use for the metadata fetching from GH. The defaults for this are set in rules_python MODULE.bazel file that one can override for a specific version.

    optional

  • netrc(str) (default “”)

    Location of the .netrc file to use for authentication

    optional

  • platform(str) (default “”)

    The platform string used in the UV repository to denote the platform triple.

    optional

  • target_settings(list[label]) (default [])

    The target_settings to add to platform definitions that then get used in toolchain definitions.

    optional

  • version(str) (default “”)

    The version of uv to configure the sources for. If this is not specified it will be the last version used in the module or the default version set by rules_python.

    optional