Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Unreleased changes template.
{obj}`--venvs_use_declare_symlink=no` to have it not create symlinks at
build time (they will be created at runtime instead).
(Fixes [#2489](https://github.com/bazelbuild/rules_python/issues/2489))
* (coverage) Fix missing files in the coverage report if they have no tests.

{#v1-2-0-added}
### Added
Expand Down
11 changes: 10 additions & 1 deletion python/private/python_bootstrap_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,21 @@ def _RunForCoverage(python_program, main_filename, args, env,
directory under the runfiles tree, and will recursively delete the
runfiles directory if set.
"""
instrumented_files = [abs_path for abs_path, _ in InstrumentedFilePaths()]
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
source = "\n\t".join(unique_dirs)

PrintVerboseCoverage("[coveragepy] Instrumented Files:\n" + "\n".join(instrumented_files))
PrintVerboseCoverage("[coveragepy] Sources:\n" + "\n".join(unique_dirs))

# We need for coveragepy to use relative paths. This can only be configured
unique_id = uuid.uuid4()
rcfile_name = os.path.join(os.environ['COVERAGE_DIR'], ".coveragerc_{}".format(unique_id))
with open(rcfile_name, "w") as rcfile:
rcfile.write('''[run]
rcfile.write(f'''[run]
relative_files = True
source =
\t{source}
''')
PrintVerboseCoverage('Coverage entrypoint:', coverage_entrypoint)
# First run the target Python file via coveragepy to create a .coverage
Expand Down
11 changes: 10 additions & 1 deletion python/private/stage2_bootstrap_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def _maybe_collect_coverage(enable):
yield
return

instrumented_files = [abs_path for abs_path, _ in instrumented_file_paths()]
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
source = "\n\t".join(unique_dirs)

print_verbose_coverage("Instrumented Files:\n" + "\n".join(instrumented_files))
print_verbose_coverage("Sources:\n" + "\n".join(unique_dirs))

import uuid

import coverage
Expand All @@ -289,8 +296,10 @@ def _maybe_collect_coverage(enable):
print_verbose_coverage("coveragerc file:", rcfile_name)
with open(rcfile_name, "w") as rcfile:
rcfile.write(
"""[run]
f"""[run]
relative_files = True
source =
\t{source}
"""
)
try:
Expand Down