Skip to content

Commit

Permalink
feat(coverage): limit support of coverage to non Windows platforms
Browse files Browse the repository at this point in the history
It seems that the support is missing upstream [3].

[3]: bazelbuild/bazel#15835
  • Loading branch information
aignas committed Jan 17, 2023
1 parent a34934c commit a0a0700
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 56 deletions.
3 changes: 0 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ use_repo(
"pypi__coverage_cp310_aarch64-apple-darwin",
"pypi__coverage_cp310_aarch64-unknown-linux-gnu",
"pypi__coverage_cp310_x86_64-apple-darwin",
"pypi__coverage_cp310_x86_64-pc-windows-msvc",
"pypi__coverage_cp310_x86_64-unknown-linux-gnu",
"pypi__coverage_cp38_aarch64-apple-darwin",
"pypi__coverage_cp38_aarch64-unknown-linux-gnu",
"pypi__coverage_cp38_x86_64-apple-darwin",
"pypi__coverage_cp38_x86_64-pc-windows-msvc",
"pypi__coverage_cp38_x86_64-unknown-linux-gnu",
"pypi__coverage_cp39_aarch64-apple-darwin",
"pypi__coverage_cp39_aarch64-unknown-linux-gnu",
"pypi__coverage_cp39_x86_64-apple-darwin",
"pypi__coverage_cp39_x86_64-pc-windows-msvc",
"pypi__coverage_cp39_x86_64-unknown-linux-gnu",
)
18 changes: 0 additions & 18 deletions python/private/coverage_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ _coverage_deps = [
"ef8674b0ee8cc11e2d574e3e2998aea5df5ab242e012286824ea3c6970580e53",
"x86_64-apple-darwin",
),
(
"pypi__coverage_cp310_x86_64-pc-windows-msvc",
"https://files.pythonhosted.org/packages/ae/a3/f45cb5d32de0751863945d22083c15eb8854bb53681b2e792f2066c629b9/coverage-6.5.0-cp310-cp310-win_amd64.whl",
"59f53f1dc5b656cafb1badd0feb428c1e7bc19b867479ff72f7a9dd9b479f10e",
"x86_64-pc-windows-msvc",
),
(
"pypi__coverage_cp310_x86_64-unknown-linux-gnu",
"https://files.pythonhosted.org/packages/3c/7d/d5211ea782b193ab8064b06dc0cc042cf1a4ca9c93a530071459172c550f/coverage-6.5.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
Expand All @@ -56,12 +50,6 @@ _coverage_deps = [
"d900bb429fdfd7f511f868cedd03a6bbb142f3f9118c09b99ef8dc9bf9643c3c",
"x86_64-apple-darwin",
),
(
"pypi__coverage_cp38_x86_64-pc-windows-msvc",
"https://files.pythonhosted.org/packages/06/f1/5177428c35f331f118e964f727f79e3a3073a10271a644c8361d3cea8bfd/coverage-6.5.0-cp38-cp38-win_amd64.whl",
"7ccf362abd726b0410bf8911c31fbf97f09f8f1061f8c1cf03dfc4b6372848f6",
"x86_64-pc-windows-msvc",
),
(
"pypi__coverage_cp38_x86_64-unknown-linux-gnu",
"https://files.pythonhosted.org/packages/bd/a0/e263b115808226fdb2658f1887808c06ac3f1b579ef5dda02309e0d54459/coverage-6.5.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
Expand All @@ -86,12 +74,6 @@ _coverage_deps = [
"633713d70ad6bfc49b34ead4060531658dc6dfc9b3eb7d8a716d5873377ab745",
"x86_64-apple-darwin",
),
(
"pypi__coverage_cp39_x86_64-pc-windows-msvc",
"https://files.pythonhosted.org/packages/b6/08/a88a9f3a11bb2d97c7a6719535a984b009728433838fbc65766488867c80/coverage-6.5.0-cp39-cp39-win_amd64.whl",
"fc2af30ed0d5ae0b1abdb4ebdce598eafd5b35397d4d75deb341a614d333d987",
"x86_64-pc-windows-msvc",
),
(
"pypi__coverage_cp39_x86_64-unknown-linux-gnu",
"https://files.pythonhosted.org/packages/6b/f2/919f0fdc93d3991ca074894402074d847be8ac1e1d78e7e9e1c371b69a6f/coverage-6.5.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
Expand Down
2 changes: 1 addition & 1 deletion python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,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 else "\"{}\"".format(rctx.attr.coverage_tool),
coverage_tool = rctx.attr.coverage_tool if rctx.attr.coverage_tool == None and "windows" not in rctx.os.name else "\"{}\"".format(rctx.attr.coverage_tool),
)
rctx.delete("python")
rctx.symlink(python_bin, "python")
Expand Down
34 changes: 12 additions & 22 deletions python/tests/toolchains/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ powershell.exe -c "& ./{interpreter_path} {run_acceptance_test_py}"
"""

def _acceptance_test_impl(ctx):
cov_suffix = "cov" if ctx.attr.register_coverage_tool else "nocov"
base = "/".join([ctx.attr.python_version, cov_suffix])
base = "/".join([ctx.attr.python_version])
workspace = ctx.actions.declare_file("/".join([base, "WORKSPACE"]))
ctx.actions.expand_template(
template = ctx.file._workspace_tmpl,
output = workspace,
substitutions = {
"%python_version%": ctx.attr.python_version,
"%register_coverage_tool%": "True" if ctx.attr.register_coverage_tool else "False",
},
)

Expand All @@ -54,7 +52,6 @@ def _acceptance_test_impl(ctx):
template = ctx.file._run_acceptance_test_tmpl,
output = run_acceptance_test_py,
substitutions = {
"%is_coverage%": str(ctx.attr.register_coverage_tool),
"%is_windows%": str(ctx.attr.is_windows),
"%python_version%": ctx.attr.python_version,
"%test_location%": "/".join([ctx.attr.test_location, base]),
Expand All @@ -68,7 +65,7 @@ def _acceptance_test_impl(ctx):
interpreter_path = py3_runtime.interpreter.short_path

if ctx.attr.is_windows:
executable = ctx.actions.declare_file("run_test_{}_{}.bat".format(ctx.attr.python_version, cov_suffix))
executable = ctx.actions.declare_file("run_test_{}.bat".format(ctx.attr.python_version))
ctx.actions.write(
output = executable,
content = _WINDOWS_RUNNER_TEMPLATE.format(
Expand All @@ -78,7 +75,7 @@ def _acceptance_test_impl(ctx):
is_executable = True,
)
else:
executable = ctx.actions.declare_file("run_test_{}_{}.sh".format(ctx.attr.python_version, cov_suffix))
executable = ctx.actions.declare_file("run_test_{}.sh".format(ctx.attr.python_version))
ctx.actions.write(
output = executable,
content = "exec '{interpreter_path}' '{run_acceptance_test_py}'".format(
Expand Down Expand Up @@ -119,10 +116,6 @@ _acceptance_test = rule(
doc = "The Python version to be used when requesting the toolchain.",
mandatory = True,
),
"register_coverage_tool": attr.bool(
doc = "Whether to register the coverage tool to the toolchain.",
mandatory = True,
),
"test_location": attr.string(
doc = "(Provided by the macro) The value of native.package_name().",
mandatory = True,
Expand Down Expand Up @@ -176,15 +169,12 @@ def acceptance_tests():
if platform not in TOOL_VERSIONS[python_version]["sha256"]:
continue

for register_coverage_tool in [True, False]:
acceptance_test(
name = "python_{python_version}_{platform}_{cov}_test".format(
python_version = python_version.replace(".", "_"),
platform = platform,
cov = "cov" if register_coverage_tool else "nocov",
),
python_version = python_version,
register_coverage_tool = register_coverage_tool,
target_compatible_with = meta.compatible_with,
tags = ["acceptance-test"],
)
acceptance_test(
name = "python_{python_version}_{platform}_test".format(
python_version = python_version.replace(".", "_"),
platform = platform,
),
python_version = python_version,
target_compatible_with = meta.compatible_with,
tags = ["acceptance-test"],
)
16 changes: 6 additions & 10 deletions python/tests/toolchains/run_acceptance_test.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ class TestPythonVersion(unittest.TestCase):
rules_python_path.replace("\\", "/")
),
"build --test_output=errors",
"coverage --java_runtime_version=remotejdk_11",
]

if %is_coverage%:
bazelrc_lines.append(
"coverage --java_runtime_version=remotejdk_11"
)

with open(".bazelrc", "w") as bazelrc:
bazelrc.write(os.linesep.join(bazelrc_lines))

Expand All @@ -57,14 +53,14 @@ class TestPythonVersion(unittest.TestCase):

subprocess.run("bazel test //...", shell=True, check=True)

if %is_coverage%:
subprocess.run("bazel coverage //...", shell=True, check=True)
return

stream = os.popen("bazel info execution_root")
exec_root = pathlib.Path(stream.read().strip())
external = exec_root / "external"
self.assertEqual([], list(external.glob("pypi__coverage_*")), "coverage toolchain should not be downloaded")
self.assertEqual([], list(external.glob("pypi__coverage_*")), "coverage toolchain should not be downloaded upon bazel test")

@unittest.skipIf(%is_windows%, "not supported on Windows")
def test_coverage_toolchain(self):
subprocess.run("bazel coverage //...", shell=True, check=True)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion python/tests/toolchains/workspace_template/WORKSPACE.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ load("@rules_python//python:repositories.bzl", "python_register_toolchains")
python_register_toolchains(
name = "python",
python_version = "%python_version%",
register_coverage_tool = %register_coverage_tool%,
)
3 changes: 2 additions & 1 deletion tools/update_coverage_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

# This should be kept in sync with //python:versions.bzl
_supported_platforms = {
"win_amd64": "x86_64-pc-windows-msvc",
# Windows is unsupported right now
# "win_amd64": "x86_64-pc-windows-msvc",
"manylinux2014_x86_64": "x86_64-unknown-linux-gnu",
"manylinux2014_aarch64": "aarch64-unknown-linux-gnu",
"macosx_11_0_arm64": "aarch64-apple-darwin",
Expand Down

0 comments on commit a0a0700

Please sign in to comment.