rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

fix(coverage): Disable certain coverage warnings.

Open phst opened this issue 5 months ago • 1 comments

These warnings appear if there are no Python source files in the instrumented directories, cf. https://github.com/bazel-contrib/rules_python/issues/2762.

Work towards #2762

phst avatar Aug 18 '25 07:08 phst

Thanks for the PR.

I think we can improve it slighty by using ctx.coverage_instrumented() and ctx.configuration.coverage_enabled. If coverage is enabled and the target isn't instrumented, then disable those warnings. Then we get the best of both worlds: if we expect coverage results, but nothing was generated, then an error (something went wrong). If we don't expect coverage data, then we can ignore it missing.

So what you'll want to do is:

  • Add a template variable to the top of the files. You should see some %blabla% markers near the top of other things. COVERAGE_INSTRUMENTED = "%coverage_instrumented%" == "1"
  • Conditionally add the disable_warnings = ... if that variable is true
  • In py_executable.bzl, pass along an additional key in the template dict. grep for %python_binary%, you should find a couple dicts in the stage1_bootstrap and stage2_bootstrap functions.

rickeylev avatar Oct 11 '25 05:10 rickeylev