Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,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
Expand Down
2 changes: 1 addition & 1 deletion python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions python/private/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -213,8 +213,10 @@ def parse_modules(*, module_ctx, logger, _fail = fail):
)

def _python_impl(module_ctx):
logger = repo_utils.logger(module_ctx, "python")
py = parse_modules(module_ctx = module_ctx, logger = logger)
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", mod = module_ctx.modules[0])

# Host compatible runtime repos
# dict[str version, struct] where struct has:
Expand Down
21 changes: 16 additions & 5 deletions python/private/repo_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -50,20 +51,30 @@ 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,
Comment thread
aignas marked this conversation as resolved.
"ERROR": -1,
"FAIL": -1,
"INFO": 1,
"TRACE": 3,
Comment thread
aignas marked this conversation as resolved.
"WARN": 0,
}.get(verbosity_level, 0)

if hasattr(mrctx, "attr"):
Expand Down