Skip to content

Commit 4e05445

Browse files
committed
Merge branch 'main' of https://github.com/bazel-contrib/rules_python into feat.build.data
2 parents b240344 + 2de083f commit 4e05445

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ END_UNRELEASED_TEMPLATE
6464

6565
{#v0-0-0-fixed}
6666
### Fixed
67-
* Nothing fixed.
67+
* (tests) No more coverage warnings are being printed if there are no sources.
68+
([#2762](https://github.com/bazel-contrib/rules_python/issues/2762))
6869

6970
{#v0-0-0-added}
7071
### Added

python/private/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ package(
2929

3030
licenses(["notice"])
3131

32+
exports_files(["runtime_env_toolchain_interpreter.sh"])
33+
3234
filegroup(
3335
name = "distribution",
3436
srcs = glob(["**"]) + [

python/private/py_executable.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ def _create_stage2_bootstrap(
678678
output = output,
679679
substitutions = {
680680
"%build_data_file%": runfiles_root_path(ctx, build_data_file.short_path),
681+
"%coverage_instrumented%": str(int(ctx.configuration.coverage_enabled and ctx.coverage_instrumented())),
681682
"%coverage_tool%": _get_coverage_tool_runfiles_path(ctx, runtime),
682683
"%import_all%": "True" if read_possibly_native_flag(ctx, "python_import_all_repositories") else "False",
683684
"%imports%": ":".join(imports.to_list()),

python/private/stage2_bootstrap_template.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@
4343
# string otherwise.
4444
VENV_SITE_PACKAGES = "%venv_rel_site_packages%"
4545

46+
# Whether we should generate coverage data.
47+
# string, 1 or 0
48+
COVERAGE_INSTRUMENTED = "%coverage_instrumented%" == "1"
49+
4650
# runfiles-root-relative path to a file with binary-specific build information
4751
BUILD_DATA_FILE = "%build_data_file%"
4852

53+
# ===== Template substitutions end =====
4954

5055
class BazelBinaryInfoModule(types.ModuleType):
5156
BUILD_DATA_FILE = BUILD_DATA_FILE
@@ -65,8 +70,6 @@ def get_build_data(self):
6570

6671
sys.modules["bazel_binary_info"] = BazelBinaryInfoModule("bazel_binary_info")
6772

68-
# ===== Template substitutions end =====
69-
7073

7174
# Return True if running on Windows
7275
def is_windows():
@@ -332,11 +335,14 @@ def _maybe_collect_coverage(enable):
332335
# We need for coveragepy to use relative paths. This can only be configured
333336
# using an rc file.
334337
rcfile_name = os.path.join(coverage_dir, ".coveragerc_{}".format(unique_id))
338+
disable_warnings = ('disable_warnings = module-not-imported, no-data-collected'
339+
if COVERAGE_INSTRUMENTED else '')
335340
print_verbose_coverage("coveragerc file:", rcfile_name)
336341
with open(rcfile_name, "w") as rcfile:
337342
rcfile.write(
338343
f"""[run]
339344
relative_files = True
345+
{disable_warnings}
340346
source =
341347
\t{source}
342348
"""

0 commit comments

Comments
 (0)