Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Test infrastructure upgrade to 3.13.2 #5517

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

Draft
wants to merge 20 commits into
base: main
Choose a base branch
Loading
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
trace.py revert
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
  • Loading branch information
arihant2math committed Feb 17, 2025
commit cb6329ed3646638152a23df3b8d3c64e5f032be2
32 changes: 23 additions & 9 deletions 32 Lib/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"""
__all__ = ['Trace', 'CoverageResults']

import io
import linecache
import os
import sys
Expand Down Expand Up @@ -201,7 +202,8 @@ def update(self, other):
for key in other_callers:
callers[key] = 1

def write_results(self, show_missing=True, summary=False, coverdir=None):
def write_results(self, show_missing=True, summary=False, coverdir=None, *,
ignore_missing_files=False):
"""
Write the coverage results.

Expand All @@ -210,6 +212,9 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
:param coverdir: If None, the results of each module are placed in its
directory, otherwise it is included in the directory
specified.
:param ignore_missing_files: If True, counts for files that no longer
exist are silently ignored. Otherwise, a missing file
will raise a FileNotFoundError.
"""
if self.calledfuncs:
print()
Expand Down Expand Up @@ -252,13 +257,15 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
if filename.endswith(".pyc"):
filename = filename[:-1]

if ignore_missing_files and not os.path.isfile(filename):
continue

if coverdir is None:
dir = os.path.dirname(os.path.abspath(filename))
modulename = _modname(filename)
else:
dir = coverdir
if not os.path.exists(dir):
os.makedirs(dir)
os.makedirs(dir, exist_ok=True)
modulename = _fullmodname(filename)

# If desired, get a list of the line numbers which represent
Expand All @@ -277,7 +284,6 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
percent = int(100 * n_hits / n_lines)
sums[modulename] = n_lines, percent, modulename, filename


if summary and sums:
print("lines cov% module (path)")
for m in sorted(sums):
Expand Down Expand Up @@ -559,8 +565,12 @@ def localtrace_trace_and_count(self, frame, why, arg):
if self.start_time:
print('%.2f' % (_time() - self.start_time), end=' ')
bname = os.path.basename(filename)
print("%s(%d): %s" % (bname, lineno,
linecache.getline(filename, lineno)), end='')
line = linecache.getline(filename, lineno)
print("%s(%d)" % (bname, lineno), end='')
if line:
print(": ", line, end='')
else:
print()
return self.localtrace

def localtrace_trace(self, frame, why, arg):
Expand All @@ -572,8 +582,12 @@ def localtrace_trace(self, frame, why, arg):
if self.start_time:
print('%.2f' % (_time() - self.start_time), end=' ')
bname = os.path.basename(filename)
print("%s(%d): %s" % (bname, lineno,
linecache.getline(filename, lineno)), end='')
line = linecache.getline(filename, lineno)
print("%s(%d)" % (bname, lineno), end='')
if line:
print(": ", line, end='')
else:
print()
return self.localtrace

def localtrace_count(self, frame, why, arg):
Expand Down Expand Up @@ -716,7 +730,7 @@ def parse_ignore_dir(s):
sys.argv = [opts.progname, *opts.arguments]
sys.path[0] = os.path.dirname(opts.progname)

with open(opts.progname, 'rb') as fp:
with io.open_code(opts.progname) as fp:
code = compile(fp.read(), opts.progname, 'exec')
# try to emulate __main__ namespace as much as possible
globs = {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.