//python/uv:uv.bzl
EXPERIMENTAL: This is experimental and may be removed without notice.
The uv toolchain extension.
- moduleextuv
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 alwaysmarked 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
uvtoolchain configuration by appending the provided configuration.The information is appended to the version configuration that is specified byversionattribute, or if the version is unspecified, the version of thelastuv.configurecall in the current module, or the version from thedefaults 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 whengenerating the authorization header for the http request. This enables the use of customauthorization 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 valuein the netrc file for the same host name. After formatting, the result is setas 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-TOKEN
The final HTTP request would have the following header:
Authorization: Bearer RANDOM-TOKEN
optional
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. Thedefaults for this are set in
rules_pythonMODULE.bazel file that one can overridefor a specific version.optional
Location of the .netrc file to use for authentication
optional
The platform string used in the UV repository to denote the platform triple.
optional
The sha256 of the downloaded artifact if the
urlsis specified.optional
target_settings–(list[label])(default[])The
target_settingsto add to platform definitions that then get used intoolchaindefinitions.optional
The urls to download the binary from. If this is used,
base_urlandmanifest_filenameare ignored for the given version.If the
urlsare specified, they need to be specified for all of the platformsfor a particular version.optional
The version of uv to configure the sources for. If this is not specified it will be thelast 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 whengenerating the authorization header for the http request. This enables the use of customauthorization 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 valuein the netrc file for the same host name. After formatting, the result is setas 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-TOKEN
The final HTTP request would have the following header:
Authorization: Bearer RANDOM-TOKEN
optional
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. Thedefaults for this are set in
rules_pythonMODULE.bazel file that one can overridefor a specific version.optional
Location of the .netrc file to use for authentication
optional
The platform string used in the UV repository to denote the platform triple.
optional
target_settings–(list[label])(default[])The
target_settingsto add to platform definitions that then get used intoolchaindefinitions.optional
The version of uv to configure the sources for. If this is not specified it will be thelast version used in the module or the default version set by
rules_python.optional