Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PYTHON_COVERAGERC env for custom configs #19656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
29 changes: 17 additions & 12 deletions tools/python/python_bootstrap_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,18 @@ def _RunForCoverage(python_program, main_filename, args, env,
directory under the runfiles tree, and will recursively delete the
runfiles directory if set.
"""
# We need for coveragepy to use relative paths. This can only be configured
# via an rc file, so we need to make one.
rcfile_name = os.path.join(os.environ['COVERAGE_DIR'], '.coveragerc')
with open(rcfile_name, "w") as rcfile:
rcfile.write('''[run]
# Allow configured coveragerc
if "PYTHON_COVERAGERC" in os.environ:
rcfile_name = os.environ["PYTHON_COVERAGERC"]
else:
# We need for coveragepy to use relative paths as default
rcfile_name = os.path.join(os.environ['COVERAGE_DIR'], '.coveragerc')
with open(rcfile_name, "w") as rcfile:
rcfile.write('''[run]
relative_files = True
''')
PrintVerboseCoverage('Coverage entrypoint:', coverage_entrypoint)
PrintVerboseCoverage('Coverage rcfile:', rcfile_name)
# First run the target Python file via coveragepy to create a .coverage
# database file, from which we can later export lcov.
ret_code = subprocess.call(
Expand Down Expand Up @@ -427,13 +431,14 @@ relative_files = True
env=env,
cwd=workspace
) or ret_code
try:
os.unlink(rcfile_name)
except OSError as err:
# It's possible that the profiled program might execute another Python
# binary through a wrapper that would then delete the rcfile. Not much
# we can do about that, besides ignore the failure here.
PrintVerboseCoverage('Error removing temporary coverage rc file:', err)
if "PYTHON_COVERAGERC" not in os.environ:
try:
os.unlink(rcfile_name)
except OSError as err:
# It's possible that the profiled program might execute another Python
# binary through a wrapper that would then delete the rcfile. Not much
# we can do about that, besides ignore the failure here.
PrintVerboseCoverage('Error removing temporary coverage rc file:', err)
if os.path.isfile(output_filename):
UnresolveSymlinks(output_filename)
return ret_code
Expand Down