diff --git a/CHANGELOG.md b/CHANGELOG.md index a2e60f70db..5f11f7d2cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,10 @@ A brief description of the categories of changes: [#2091](https://github.com/bazelbuild/rules_python/issues/2090). * (gazelle) Make `gazelle_python_manifest.update` manual to avoid unnecessary network behavior. +* (bzlmod): The conflicting toolchains during `python` extension will no longer + cause warnings by default. In order to see the warnings for diagnostic purposes + set the env var `RULES_PYTHON_REPO_DEBUG_VERBOSITY` to one of `INFO`, `DEBUG` or `TRACE`. + Fixes [#1818](https://github.com/bazelbuild/rules_python/issues/1818). ### Added * (rules) `PYTHONSAFEPATH` is inherited from the calling environment to allow diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 3b97a02ed9..146e934654 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -132,6 +132,7 @@ bzl_library( srcs = ["python.bzl"], deps = [ ":pythons_hub_bzl", + ":repo_utils_bzl", ":toolchains_repo_bzl", ":util_bzl", "//python:repositories_bzl", diff --git a/python/private/python.bzl b/python/private/python.bzl index ce00a7bb74..6a265d1395 100644 --- a/python/private/python.bzl +++ b/python/private/python.bzl @@ -17,6 +17,7 @@ load("@bazel_features//:features.bzl", "bazel_features") load("//python:repositories.bzl", "python_register_toolchains") load("//python:versions.bzl", "TOOL_VERSIONS") +load("//python/private:repo_utils.bzl", "repo_utils") load(":pythons_hub.bzl", "hub_repo") load(":text_util.bzl", "render") load(":toolchains_repo.bzl", "multi_toolchain_aliases") @@ -27,12 +28,6 @@ load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER") _MAX_NUM_TOOLCHAINS = 9999 _TOOLCHAIN_INDEX_PAD_LENGTH = len(str(_MAX_NUM_TOOLCHAINS)) -# Printing a warning msg not debugging, so we have to disable -# the buildifier check. -# buildifier: disable=print -def _print_warn(msg): - print("WARNING:", msg) - def _python_register_toolchains(name, toolchain_attr, module, ignore_root_user_error): """Calls python_register_toolchains and returns a struct used to collect the toolchains. """ @@ -71,6 +66,8 @@ def _python_impl(module_ctx): ignore_root_user_error = None + logger = repo_utils.logger(module_ctx, "python") + # if the root module does not register any toolchain then the # ignore_root_user_error takes its default value: False if not module_ctx.modules[0].tags.toolchain: @@ -131,11 +128,14 @@ def _python_impl(module_ctx): # version that rules_python provides as default. first = global_toolchain_versions[toolchain_version] if mod.name != "rules_python" or not first.module.is_root: + # The warning can be enabled by setting the verbosity: + # env RULES_PYTHON_REPO_DEBUG_VERBOSITY=INFO bazel build //... _warn_duplicate_global_toolchain_version( toolchain_version, first = first, second_toolchain_name = toolchain_name, second_module_name = mod.name, + logger = logger, ) toolchain_info = None else: @@ -231,11 +231,11 @@ def _fail_duplicate_module_toolchain_version(version, module): module = module, )) -def _warn_duplicate_global_toolchain_version(version, first, second_toolchain_name, second_module_name): - _print_warn(( +def _warn_duplicate_global_toolchain_version(version, first, second_toolchain_name, second_module_name, logger): + logger.info(lambda: ( "Ignoring toolchain '{second_toolchain}' from module '{second_module}': " + "Toolchain '{first_toolchain}' from module '{first_module}' " + - "already registered Python version {version} and has precedence" + "already registered Python version {version} and has precedence." ).format( first_toolchain = first.name, first_module = first.module.name,