Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bazel-contrib/rules_python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.18.0
Choose a base ref
...
head repository: bazel-contrib/rules_python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.18.1
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Feb 14, 2023

  1. Only set py_runtime.coverage_tool for Bazel 6 and higher. (#1061)

    Only set `py_runtime.coverage_tool` for Bazel 6 and higher.
    
    Avoid setting it in earlier version by checking `native.bazel_version`
    in the repository rule and disabling it if less than Bazel 6 is
    detected. A warning is also printed if coverage was requested, but
    the Bazel version check is ignoring it.
    
    Fixes #1056
    rickeylev committed Feb 14, 2023
    Copy the full SHA
    9ad0674 View commit details
Showing with 32 additions and 5 deletions.
  1. +32 −5 python/repositories.bzl
37 changes: 32 additions & 5 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
@@ -243,6 +243,21 @@ def _python_repository_impl(rctx):
"share/**",
]

if rctx.attr.coverage_tool:
if "windows" in rctx.os.name:
coverage_tool = None
else:
coverage_tool = '"{}"'.format(rctx.attr.coverage_tool)

coverage_attr_text = """\
coverage_tool = select({{
":coverage_enabled": {coverage_tool},
"//conditions:default": None
}}),
""".format(coverage_tool = coverage_tool)
else:
coverage_attr_text = " # coverage_tool attribute not supported by this Bazel version"

build_content = """\
# Generated by python/repositories.bzl
@@ -308,10 +323,7 @@ config_setting(
py_runtime(
name = "py3_runtime",
files = [":files"],
coverage_tool = select({{
":coverage_enabled": {coverage_tool},
"//conditions:default": None,
}}),
{coverage_attr}
interpreter = "{python_path}",
python_version = "PY3",
)
@@ -327,7 +339,7 @@ py_runtime_pair(
python_path = python_bin,
python_version = python_short_version,
python_version_nodot = python_short_version.replace(".", ""),
coverage_tool = rctx.attr.coverage_tool if rctx.attr.coverage_tool == None or "windows" in rctx.os.name else "\"{}\"".format(rctx.attr.coverage_tool),
coverage_attr = coverage_attr_text,
)
rctx.delete("python")
rctx.symlink(python_bin, "python")
@@ -459,6 +471,8 @@ def python_register_toolchains(
distutils_content: see the distutils_content attribute in the python_repository repository rule.
register_toolchains: Whether or not to register the downloaded toolchains.
register_coverage_tool: Whether or not to register the downloaded coverage tool to the toolchains.
NOTE: Coverage support using the toolchain is only supported in Bazel 6 and higher.
set_python_version_constraint: When set to true, target_compatible_with for the toolchains will include a version constraint.
tool_versions: a dict containing a mapping of version with SHASUM and platform info. If not supplied, the defaults
in python/versions.bzl will be used.
@@ -472,6 +486,19 @@ def python_register_toolchains(

toolchain_repo_name = "{name}_toolchains".format(name = name)

bazel_major = int(native.bazel_version.split(".")[0])
if bazel_major < 6:
if register_coverage_tool:
# buildifier: disable=print
print((
"WARNING: ignoring register_coverage_tool=True when " +
"registering @{name}: Bazel 6+ required, got {version}"
).format(
name = name,
version = native.bazel_version,
))
register_coverage_tool = False

for platform in PLATFORMS.keys():
sha256 = tool_versions[python_version]["sha256"].get(platform, None)
if not sha256: