fix(coverage): Disable certain coverage warnings. by phst · Pull Request #3191 · bazel-contrib/rules_python

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.