Skip to content

Commit 76786dc

Browse files
committed
move source to .coveragerc file
1 parent 088e182 commit 76786dc

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

python/private/python_bootstrap_template.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,22 +425,22 @@ def _RunForCoverage(python_program, main_filename, args, env,
425425
directory under the runfiles tree, and will recursively delete the
426426
runfiles directory if set.
427427
"""
428+
instrumented_files = [abs_path for abs_path, _ in InstrumentedFilePaths()]
429+
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
430+
431+
PrintVerboseCoverage("[coveragepy] Instrumented Files:\n" + "\n".join(instrumented_files))
432+
PrintVerboseCoverage("[coveragepy] Sources:\n" + "\n".join(unique_dirs))
433+
428434
# We need for coveragepy to use relative paths. This can only be configured
429435
unique_id = uuid.uuid4()
430436
rcfile_name = os.path.join(os.environ['COVERAGE_DIR'], ".coveragerc_{}".format(unique_id))
431437
with open(rcfile_name, "w") as rcfile:
432-
rcfile.write('''[run]
438+
rcfile.write(f'''[run]
433439
relative_files = True
440+
source =
441+
\t{"\n\t".join(unique_dirs)}
434442
''')
435443
PrintVerboseCoverage('Coverage entrypoint:', coverage_entrypoint)
436-
437-
instrumented_files = [abs_path for abs_path, _ in InstrumentedFilePaths()]
438-
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
439-
source = ",".join(unique_dirs)
440-
441-
PrintVerboseCoverage("[coveragepy] Instrumented Files:\n" + "\n".join(instrumented_files))
442-
PrintVerboseCoverage("[coveragepy] Sources:\n" + "\n".join(unique_dirs))
443-
444444
# First run the target Python file via coveragepy to create a .coverage
445445
# database file, from which we can later export lcov.
446446
ret_code = subprocess.call(
@@ -451,7 +451,6 @@ relative_files = True
451451
"--rcfile=" + rcfile_name,
452452
"--append",
453453
"--branch",
454-
"--source=" + source,
455454
main_filename
456455
] + args,
457456
env=env,

python/private/stage2_bootstrap_template.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ def _maybe_collect_coverage(enable):
276276
yield
277277
return
278278

279+
instrumented_files = [abs_path for abs_path, _ in instrumented_file_paths()]
280+
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
281+
282+
print_verbose_coverage("Instrumented Files:\n" + "\n".join(instrumented_files))
283+
print_verbose_coverage("Sources:\n" + "\n".join(unique_dirs))
284+
279285
import uuid
280286

281287
import coverage
@@ -289,18 +295,12 @@ def _maybe_collect_coverage(enable):
289295
print_verbose_coverage("coveragerc file:", rcfile_name)
290296
with open(rcfile_name, "w") as rcfile:
291297
rcfile.write(
292-
"""[run]
298+
f"""[run]
293299
relative_files = True
300+
source =
301+
\t{"\n\t".join(unique_dirs)}
294302
"""
295303
)
296-
297-
instrumented_files = [abs_path for abs_path, _ in instrumented_file_paths()]
298-
unique_dirs = {os.path.dirname(file) for file in instrumented_files}
299-
source = list(unique_dirs)
300-
301-
print_verbose_coverage("Instrumented Files:\n" + "\n".join(instrumented_files))
302-
print_verbose_coverage("Sources:\n" + "\n".join(unique_dirs))
303-
304304
try:
305305
cov = coverage.Coverage(
306306
config_file=rcfile_name,
@@ -322,7 +322,6 @@ def _maybe_collect_coverage(enable):
322322
# see https://github.com/nedbat/coveragepy/blob/bfb0c708fdd8182b2a9f0fc403596693ef65e475/coverage/inorout.py#L153-L164
323323
"*/external/*",
324324
],
325-
source=source,
326325
)
327326
cov.start()
328327
try:

0 commit comments

Comments
 (0)