From 198e46c7846ea543ebf008e4d4cb70a006f2cea1 Mon Sep 17 00:00:00 2001 From: chrislovecnm Date: Tue, 9 May 2023 08:46:29 -0600 Subject: [PATCH] feat(bzlmod): Adding base_url attr to python.toolchain The base_url attribute allows a user to override the URL that is passed into python_register_toolchains, via kwargs. This URL is then passed to python_repository which enables the download of a Python installation package from a custom URL. A user is now able to set a custom location that hosts the Python binaries. --- python/extensions.bzl | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/python/extensions.bzl b/python/extensions.bzl index 3bcbb5023d..ebacb5dd0b 100644 --- a/python/extensions.bzl +++ b/python/extensions.bzl @@ -24,15 +24,27 @@ load("@rules_python//python/private:toolchains_repo.bzl", "get_host_os_arch", "g def _python_impl(module_ctx): for mod in module_ctx.modules: for toolchain_attr in mod.tags.toolchain: - python_register_toolchains( - name = toolchain_attr.name, - python_version = toolchain_attr.python_version, - bzlmod = True, - # Toolchain registration in bzlmod is done in MODULE file - register_toolchains = False, - register_coverage_tool = toolchain_attr.configure_coverage_tool, - ignore_root_user_error = toolchain_attr.ignore_root_user_error, - ) + if toolchain_attr.base_url: + python_register_toolchains( + name = toolchain_attr.name, + python_version = toolchain_attr.python_version, + bzlmod = True, + # Toolchain registration in bzlmod is done in MODULE file + register_toolchains = False, + register_coverage_tool = toolchain_attr.configure_coverage_tool, + ignore_root_user_error = toolchain_attr.ignore_root_user_error, + base_url = toolchain_attr.base_url, + ) + else: + python_register_toolchains( + name = toolchain_attr.name, + python_version = toolchain_attr.python_version, + bzlmod = True, + # Toolchain registration in bzlmod is done in MODULE file + register_toolchains = False, + register_coverage_tool = toolchain_attr.configure_coverage_tool, + ignore_root_user_error = toolchain_attr.ignore_root_user_error, + ) host_hub_name = toolchain_attr.name + "_host_interpreter" _host_hub( name = host_hub_name, @@ -44,6 +56,14 @@ python = module_extension( tag_classes = { "toolchain": tag_class( attrs = { + "base_url": attr.string( + mandatory = False, + doc = """\ +The URL that is used to override rules_python DEFAULT_RELEASE_BASE_URL. This rule set downloads +the different Python binaries from this website. Override this URL if you want to have rules_python +download the hermetic versions of Python from a different website. +""", + ), "configure_coverage_tool": attr.bool( mandatory = False, doc = "Whether or not to configure the default coverage tool for the toolchains.",