From 6c461904863d056a14f1b1d8b95f85040d2b7e12 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Fri, 8 May 2026 12:48:50 +0900 Subject: [PATCH 1/5] fix(logger): do not output WARN level logs for non-root modules A user has reported issues which actually resulted from a particular `bazel` version being used and once he updated, the issues disappeared because of changes in implicit non-root module dependencies. In order to reduce the warning spam of non-root modules, set the default level to `ERROR` for non-root module parsing context and `WARN` for root module context. This means that the users will not get console output that they have no way to fix without patching upstream dependencies. At the same time ensure that the name of the module is printed together with the logs to better understand where something is coming from. Fixes #3749 --- CHANGELOG.md | 2 ++ python/private/pypi/extension.bzl | 2 +- python/private/python.bzl | 8 +++++--- python/private/repo_utils.bzl | 19 ++++++++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c102d3b04e..d45eca1322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,8 @@ END_UNRELEASED_TEMPLATE * (pypi) Fix `importlib.metadata.files` by ensuring `RECORD` is included in installed wheel targets, except when built from sdist ([#3024](https://github.com/bazel-contrib/rules_python/issues/3024)). +* (bzlmod) Reduce default verbosity of our loggers for non-root modules + ([#3749](https://github.com/bazel-contrib/rules_python/issues/3749)). {#v0-0-0-added} diff --git a/python/private/pypi/extension.bzl b/python/private/pypi/extension.bzl index e6052782fa..2a8ace28f2 100644 --- a/python/private/pypi/extension.bzl +++ b/python/private/pypi/extension.bzl @@ -358,7 +358,7 @@ You cannot use both the additive_build_content and additive_build_content_file a minor_mapping = kwargs.get("minor_mapping", MINOR_MAPPING), evaluate_markers_fn = kwargs.get("evaluate_markers", None), available_interpreters = kwargs.get("available_interpreters", INTERPRETER_LABELS), - logger = repo_utils.logger(module_ctx, "pypi:hub:" + hub_name), + logger = repo_utils.logger(module_ctx, "pypi:hub:" + hub_name, mod = mod), ) pip_hub_map[pip_attr.hub_name] = builder elif pip_hub_map[hub_name].module_name != mod.name: diff --git a/python/private/python.bzl b/python/private/python.bzl index 2ea757892e..7d38652e19 100644 --- a/python/private/python.bzl +++ b/python/private/python.bzl @@ -31,7 +31,7 @@ load( ) load(":version.bzl", "version") -def parse_modules(*, module_ctx, logger, _fail = fail): +def parse_modules(*, module_ctx, logger = None, _fail = fail): """Parse the modules and return a struct for registrations. Args: @@ -137,7 +137,7 @@ def parse_modules(*, module_ctx, logger, _fail = fail): first = first, second_toolchain_name = toolchain_name, second_module_name = mod.name, - logger = logger, + logger = logger or repo_utils.logger(module_ctx, "python", mod = mod), ) toolchain_info = None else: @@ -213,8 +213,10 @@ def parse_modules(*, module_ctx, logger, _fail = fail): ) def _python_impl(module_ctx): + py = parse_modules(module_ctx = module_ctx) + + # For all other processing(after parsing the modules) let's use a single logger. logger = repo_utils.logger(module_ctx, "python") - py = parse_modules(module_ctx = module_ctx, logger = logger) # Host compatible runtime repos # dict[str version, struct] where struct has: diff --git a/python/private/repo_utils.bzl b/python/private/repo_utils.bzl index ae2fc2e5d0..33783f8efc 100644 --- a/python/private/repo_utils.bzl +++ b/python/private/repo_utils.bzl @@ -31,7 +31,7 @@ def _is_repo_debug_enabled(mrctx): """ return mrctx.getenv(REPO_DEBUG_ENV_VAR) == "1" -def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): +def _logger(mrctx = None, name = None, verbosity_level = None, printer = None, mod = None): """Creates a logger instance for printing messages. Args: @@ -42,6 +42,7 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): taken from `mrctx`. printer: a function to use for printing. Defaults to `print` or `fail` depending on the logging method. + mod: {type}`module_ctx.module`. The module for which the logger is created. Returns: A struct with attributes logging: trace, debug, info, warn, fail. @@ -50,14 +51,22 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None): the logger injected into the function work as expected by terminating on the given line. """ + default_verbosity_level = "WARN" + if mod: + if name: + name = "{}:{}".format(mod.name, name) + else: + name = mod.name + + if not mod.is_root: + default_verbosity_level = "ERROR" # the warnings are non actionable anyway, but we should keep them. + if verbosity_level == None: if _is_repo_debug_enabled(mrctx): - verbosity_level = "DEBUG" - else: - verbosity_level = "WARN" + default_verbosity_level = "DEBUG" env_var_verbosity = mrctx.getenv(REPO_VERBOSITY_ENV_VAR) - verbosity_level = env_var_verbosity or verbosity_level + verbosity_level = env_var_verbosity or default_verbosity_level verbosity = { "DEBUG": 2, From 5e95d5eeb4a9d3d001a2e3dbd152251da250d09e Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sat, 9 May 2026 07:33:46 +0900 Subject: [PATCH 2/5] comment: set the error levels correctly Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- python/private/repo_utils.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/private/repo_utils.bzl b/python/private/repo_utils.bzl index 33783f8efc..c60def89ac 100644 --- a/python/private/repo_utils.bzl +++ b/python/private/repo_utils.bzl @@ -70,6 +70,8 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None, m verbosity = { "DEBUG": 2, + "ERROR": -1, + "WARN": 0, "FAIL": -1, "INFO": 1, "TRACE": 3, From 22c427171bc3dad6b9031b2ca20c375f3ad491b8 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 10 May 2026 14:27:57 +0900 Subject: [PATCH 3/5] Update python/private/python.bzl Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- python/private/python.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/private/python.bzl b/python/private/python.bzl index 7d38652e19..0f12f88f0c 100644 --- a/python/private/python.bzl +++ b/python/private/python.bzl @@ -215,8 +215,8 @@ def parse_modules(*, module_ctx, logger = None, _fail = fail): def _python_impl(module_ctx): py = parse_modules(module_ctx = module_ctx) - # For all other processing(after parsing the modules) let's use a single logger. - logger = repo_utils.logger(module_ctx, "python") + # For all other processing (after parsing the modules) let's use a single logger. + logger = repo_utils.logger(module_ctx, "python", mod = module_ctx.modules[0]) # Host compatible runtime repos # dict[str version, struct] where struct has: From ee40b931f02705142926c76b84fdd00c17818c6b Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 10 May 2026 15:14:45 +0900 Subject: [PATCH 4/5] move changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf55a2057..3feaebf428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,8 +80,6 @@ END_UNRELEASED_TEMPLATE * (pypi) Fix `importlib.metadata.files` by ensuring `RECORD` is included in installed wheel targets, except when built from sdist ([#3024](https://github.com/bazel-contrib/rules_python/issues/3024)). -* (bzlmod) Reduce default verbosity of our loggers for non-root modules - ([#3749](https://github.com/bazel-contrib/rules_python/issues/3749)). {#v0-0-0-added} @@ -117,6 +115,8 @@ END_UNRELEASED_TEMPLATE * (pypi) Fix the versions of packages that we are recording to a `MODULE.bazel.lock` file facts by passing all of the versions to the `get_index` function. Fixes [#3756](https://github.com/bazel-contrib/rules_python/issues/3756). +* (bzlmod) Reduce default verbosity of our loggers for non-root modules + ([#3749](https://github.com/bazel-contrib/rules_python/issues/3749)). {#v2-0-0} ## [2.0.0] - 2026-04-09 From 2d759b0ba5fd9f8fc40091c2f9f9a8bfa16d2d02 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 10 May 2026 15:33:20 +0900 Subject: [PATCH 5/5] Sort the dict --- python/private/repo_utils.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/repo_utils.bzl b/python/private/repo_utils.bzl index c60def89ac..6fa851b7b3 100644 --- a/python/private/repo_utils.bzl +++ b/python/private/repo_utils.bzl @@ -71,10 +71,10 @@ def _logger(mrctx = None, name = None, verbosity_level = None, printer = None, m verbosity = { "DEBUG": 2, "ERROR": -1, - "WARN": 0, "FAIL": -1, "INFO": 1, "TRACE": 3, + "WARN": 0, }.get(verbosity_level, 0) if hasattr(mrctx, "attr"):