Skip to content
Open
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
3 changes: 3 additions & 0 deletions news/2570.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(bzlmod) Fixed a type mismatch error when using {obj}`coverage_tool` with
{obj}`python.single_version_platform_override`
([#2570](https://github.com/bazel-contrib/rules_python/issues/2570)).
5 changes: 4 additions & 1 deletion python/private/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,10 @@ def _process_single_version_platform_overrides(*, tag, _fail = fail, default):
available_versions[tag.python_version] = {}

if tag.coverage_tool:
available_versions[tag.python_version].setdefault("coverage_tool", {})[tag.platform] = tag.coverage_tool
# NOTE: tag.coverage_tool is a Label (so that it is resolved relative to the
# calling module), but downstream (python_repository.coverage_tool) it is
# consumed as a string, so convert it to its canonical string form here.
available_versions[tag.python_version].setdefault("coverage_tool", {})[tag.platform] = str(tag.coverage_tool)
if tag.patch_strip:
available_versions[tag.python_version].setdefault("patch_strip", {})[tag.platform] = tag.patch_strip
if tag.patches:
Expand Down
15 changes: 13 additions & 2 deletions tests/python/python_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ def _test_add_new_version(env):
],
single_version_platform_override = [
python_ext.single_version_platform_override(
coverage_tool = "specific_cov_tool",
# `coverage_tool` is declared as `attr.label` on the tag class
# (so bzlmod resolves it relative to the calling module), so it
# is a `Label`, not a plain `str`, by the time it reaches here.
# See https://github.com/bazel-contrib/rules_python/issues/2570.
coverage_tool = Label("@my_module//:specific_cov_tool"),
patch_strip = 2,
patches = ["specific-patch.txt"],
platform = "aarch64-unknown-linux-gnu",
Expand Down Expand Up @@ -509,8 +513,15 @@ def _test_add_new_version(env):
"strip_prefix": {"aarch64-unknown-linux-gnu": "prefix"},
"url": {"aarch64-unknown-linux-gnu": ["example.org"]},
})

# The Label must be converted to its canonical string form: `python_repository`
# (which ultimately consumes this value) declares `coverage_tool` as `attr.string`.
coverage_tool = py.config.default["tool_versions"]["3.13.99"]["coverage_tool"]["aarch64-unknown-linux-gnu"]
env.expect.that_str(type(coverage_tool)).equals("string")
env.expect.that_str(coverage_tool).equals(str(Label("@my_module//:specific_cov_tool")))

env.expect.that_dict(py.config.default["tool_versions"]["3.13.99"]).contains_exactly({
"coverage_tool": {"aarch64-unknown-linux-gnu": "specific_cov_tool"},
"coverage_tool": {"aarch64-unknown-linux-gnu": coverage_tool},
"patch_strip": {"aarch64-unknown-linux-gnu": 2},
"patches": {"aarch64-unknown-linux-gnu": ["specific-patch.txt"]},
"sha256": {"aarch64-unknown-linux-gnu": "deadb00f"},
Expand Down