Skip to content

Commit

Permalink
refactor: Address a few improvements on uv toolchain (#2062)
Browse files Browse the repository at this point in the history
Follows: #1989

Addresses the following:
* Removes usage of `maybe`
* Pretty-print renders some generated *.bazel
* Shorter default_repo_names
  • Loading branch information
groodt authored Jul 13, 2024
1 parent eeb7494 commit 43a32a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions python/uv/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ bzl_library(
name = "toolchains_repo",
srcs = ["toolchains_repo.bzl"],
visibility = ["//python/uv:__subpackages__"],
deps = [
"//python/private:text_util_bzl",
],
)

bzl_library(
Expand Down
4 changes: 3 additions & 1 deletion python/uv/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

"Creates a repository to hold toolchains"

load("//python/private:text_util.bzl", "render")

_TOOLCHAIN_TEMPLATE = """
toolchain(
name = "{name}",
Expand All @@ -33,7 +35,7 @@ def _toolchains_repo_impl(repository_ctx):
name = toolchain_name,
toolchain_type = repository_ctx.attr.toolchain_type,
toolchain_label = toolchain_label,
compatible_with = json.encode(toolchain_compatible_with),
compatible_with = render.list(toolchain_compatible_with),
)

repository_ctx.file("BUILD.bazel", build_content)
Expand Down
14 changes: 7 additions & 7 deletions python/uv/private/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,49 @@

UV_PLATFORMS = {
"aarch64-apple-darwin": struct(
default_repo_name = "rules_python_uv_darwin_aarch64",
default_repo_name = "uv_darwin_aarch64",
compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
),
"aarch64-unknown-linux-gnu": struct(
default_repo_name = "rules_python_uv_linux_aarch64",
default_repo_name = "uv_linux_aarch64",
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
),
"powerpc64le-unknown-linux-gnu": struct(
default_repo_name = "rules_python_uv_linux_ppc",
default_repo_name = "uv_linux_ppc",
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
),
"s390x-unknown-linux-gnu": struct(
default_repo_name = "rules_python_uv_linux_s390x",
default_repo_name = "uv_linux_s390x",
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
),
"x86_64-apple-darwin": struct(
default_repo_name = "rules_python_uv_darwin_x86_64",
default_repo_name = "uv_darwin_x86_64",
compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
),
"x86_64-pc-windows-msvc": struct(
default_repo_name = "rules_python_uv_windows_x86_64",
default_repo_name = "uv_windows_x86_64",
compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
),
"x86_64-unknown-linux-gnu": struct(
default_repo_name = "rules_python_uv_linux_x86_64",
default_repo_name = "uv_linux_x86_64",
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
Expand Down
4 changes: 1 addition & 3 deletions python/uv/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ EXPERIMENTAL: This is experimental and may be removed without notice
Create repositories for uv toolchain dependencies
"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//python/uv/private:toolchain_types.bzl", "UV_TOOLCHAIN_TYPE")
load("//python/uv/private:toolchains_repo.bzl", "uv_toolchains_repo")
load("//python/uv/private:versions.bzl", "UV_PLATFORMS", "UV_TOOL_VERSIONS")
Expand Down Expand Up @@ -98,8 +97,7 @@ def uv_register_toolchains(uv_version = None, register_toolchains = True):
for platform in UV_PLATFORMS.keys():
uv_repository_name = UV_PLATFORMS[platform].default_repo_name

maybe(
uv_repository,
uv_repository(
name = uv_repository_name,
uv_version = uv_version,
platform = platform,
Expand Down

0 comments on commit 43a32a3

Please sign in to comment.