blob: 1c888acd99f3ccfc3c6f77915669f5ff13b8295b [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#!/usr/bin/env python3
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +00002
3# portions copyright 2001, Autonomous Zones Industries, Inc., all rights...
4# err... reserved and offered to the public under the terms of the
5# Python 2.2 license.
6# Author: Zooko O'Whielacronx
7# http://zooko.com/
8# mailto:zooko@zooko.com
9#
10# Copyright 2000, Mojam Media, Inc., all rights reserved.
11# Author: Skip Montanaro
12#
13# Copyright 1999, Bioreason, Inc., all rights reserved.
14# Author: Andrew Dalke
15#
16# Copyright 1995-1997, Automatrix, Inc., all rights reserved.
17# Author: Skip Montanaro
18#
19# Copyright 1991-1995, Stichting Mathematisch Centrum, all rights reserved.
20#
21#
22# Permission to use, copy, modify, and distribute this Python software and
23# its associated documentation for any purpose without fee is hereby
24# granted, provided that the above copyright notice appears in all copies,
25# and that both that copyright notice and this permission notice appear in
26# supporting documentation, and that the name of neither Automatrix,
27# Bioreason or Mojam Media be used in advertising or publicity pertaining to
28# distribution of the software without specific, written prior permission.
29#
30"""program/module to trace Python program or function execution
31
32Sample use, command line:
33 trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
34 trace.py -t --ignore-dir '$prefix' spam.py eggs
Skip Montanaro5bfd9842004-04-10 16:29:58 +000035 trace.py --trackcalls spam.py eggs
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000036
37Sample use, programmatically
Thomas Wouters477c8d52006-05-27 19:21:47 +000038 import sys
39
40 # create a Trace object, telling it what to ignore, and whether to
41 # do tracing or line-counting or both.
Vinay Sajip7ded1f02012-05-26 03:45:29 +010042 tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,],
43 trace=0, count=1)
Thomas Wouters477c8d52006-05-27 19:21:47 +000044 # run the new command using the given tracer
45 tracer.run('main()')
46 # make a report, placing output in /tmp
47 r = tracer.results()
48 r.write_results(show_missing=True, coverdir="/tmp")
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000049"""
Alexander Belopolsky44454af2010-11-20 18:21:07 +000050__all__ = ['Trace', 'CoverageResults']
Jeremy Hylton38732e12003-04-21 22:04:46 +000051import linecache
Jeremy Hylton38732e12003-04-21 22:04:46 +000052import os
53import re
54import sys
55import token
56import tokenize
Alexander Belopolsky4d770172010-09-13 18:14:34 +000057import inspect
Skip Montanaro5bfd9842004-04-10 16:29:58 +000058import gc
Alexander Belopolskyff09ce22010-09-24 18:03:12 +000059import dis
Guido van Rossum99603b02007-07-20 00:22:32 +000060import pickle
Ezio Melotti23e043f2013-02-15 21:20:50 +020061from warnings import warn as _warn
Victor Stinner949d8c92012-05-30 13:30:32 +020062try:
63 from time import monotonic as _time
Brett Cannoncd171c82013-07-04 17:43:24 -040064except ImportError:
Victor Stinner949d8c92012-05-30 13:30:32 +020065 from time import time as _time
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000066
Alexander Belopolsky25b57412010-11-06 01:31:16 +000067try:
68 import threading
Brett Cannoncd171c82013-07-04 17:43:24 -040069except ImportError:
Alexander Belopolsky25b57412010-11-06 01:31:16 +000070 _settrace = sys.settrace
71
72 def _unsettrace():
73 sys.settrace(None)
74else:
75 def _settrace(func):
76 threading.settrace(func)
77 sys.settrace(func)
78
79 def _unsettrace():
80 sys.settrace(None)
81 threading.settrace(None)
82
Alexander Belopolsky44454af2010-11-20 18:21:07 +000083def _usage(outfile):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000084 outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
85
86Meta-options:
87--help Display this help then exit.
88--version Output version information then exit.
89
90Otherwise, exactly one of the following three options must be given:
91-t, --trace Print each line to sys.stdout before it is executed.
92-c, --count Count the number of times each line is executed
93 and write the counts to <module>.cover for each
94 module executed, in the module's directory.
95 See also `--coverdir', `--file', `--no-report' below.
Skip Montanaroa7b8ac62003-06-27 19:09:33 +000096-l, --listfuncs Keep track of which functions are executed at least
Fred Drake01c623b2003-06-27 19:22:11 +000097 once and write the results to sys.stdout after the
Skip Montanaroa7b8ac62003-06-27 19:09:33 +000098 program exits.
Skip Montanarocafc8112004-04-07 15:46:05 +000099-T, --trackcalls Keep track of caller/called pairs and write the
100 results to sys.stdout after the program exits.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000101-r, --report Generate a report from a counts file; do not execute
102 any code. `--file' must specify the results file to
103 read, which must have been created in a previous run
104 with `--count --file=FILE'.
105
106Modifiers:
107-f, --file=<file> File to accumulate counts over several runs.
108-R, --no-report Do not generate the coverage report files.
109 Useful if you want to accumulate over several runs.
110-C, --coverdir=<dir> Directory where the report files. The coverage
111 report for <package>.<module> is written to file
112 <dir>/<package>/<module>.cover.
113-m, --missing Annotate executable lines that were not executed
114 with '>>>>>> '.
115-s, --summary Write a brief summary on stdout for each file.
116 (Can only be used with --count or --report.)
Christian Heimes380f7f22008-02-28 11:19:05 +0000117-g, --timing Prefix each line with the time since the program started.
118 Only used while tracing.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000119
120Filters, may be repeated multiple times:
Georg Brandlfceab5a2008-01-19 20:08:23 +0000121--ignore-module=<mod> Ignore the given module(s) and its submodules
122 (if it is a package). Accepts comma separated
123 list of module names
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000124--ignore-dir=<dir> Ignore files in the given directory (multiple
125 directories can be joined by os.pathsep).
126""" % sys.argv[0])
127
Jeremy Hylton38732e12003-04-21 22:04:46 +0000128PRAGMA_NOCOVER = "#pragma NO COVER"
129
130# Simple rx to find lines with no code.
131rx_blank = re.compile(r'^\s*(#.*)?$')
132
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000133class _Ignore:
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000134 def __init__(self, modules=None, dirs=None):
135 self._mods = set() if not modules else set(modules)
136 self._dirs = [] if not dirs else [os.path.normpath(d)
137 for d in dirs]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000138 self._ignore = { '<string>': 1 }
139
140 def names(self, filename, modulename):
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000141 if modulename in self._ignore:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000142 return self._ignore[modulename]
143
144 # haven't seen this one before, so see if the module name is
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000145 # on the ignore list.
146 if modulename in self._mods: # Identical names, so ignore
147 self._ignore[modulename] = 1
148 return 1
149
150 # check if the module is a proper submodule of something on
151 # the ignore list
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000152 for mod in self._mods:
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000153 # Need to take some care since ignoring
154 # "cmp" mustn't mean ignoring "cmpcache" but ignoring
155 # "Spam" must also mean ignoring "Spam.Eggs".
156 if modulename.startswith(mod + '.'):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000157 self._ignore[modulename] = 1
158 return 1
159
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000160 # Now check that filename isn't in one of the directories
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000161 if filename is None:
162 # must be a built-in, so we must ignore
163 self._ignore[modulename] = 1
164 return 1
165
166 # Ignore a file when it contains one of the ignorable paths
167 for d in self._dirs:
168 # The '+ os.sep' is to ensure that d is a parent directory,
169 # as compared to cases like:
170 # d = "/usr/local"
171 # filename = "/usr/local.py"
172 # or
173 # d = "/usr/local.py"
174 # filename = "/usr/local.py"
175 if filename.startswith(d + os.sep):
176 self._ignore[modulename] = 1
177 return 1
178
179 # Tried the different ways, so we don't ignore this module
180 self._ignore[modulename] = 0
181 return 0
182
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000183def _modname(path):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000184 """Return a plausible module name for the patch."""
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000185
Jeremy Hylton38732e12003-04-21 22:04:46 +0000186 base = os.path.basename(path)
187 filename, ext = os.path.splitext(base)
188 return filename
189
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000190def _fullmodname(path):
Jeremy Hyltonc8c8b942003-04-22 15:35:51 +0000191 """Return a plausible module name for the path."""
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000192
193 # If the file 'path' is part of a package, then the filename isn't
194 # enough to uniquely identify it. Try to do the right thing by
195 # looking in sys.path for the longest matching prefix. We'll
196 # assume that the rest is the package name.
197
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000198 comparepath = os.path.normcase(path)
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000199 longest = ""
200 for dir in sys.path:
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000201 dir = os.path.normcase(dir)
202 if comparepath.startswith(dir) and comparepath[len(dir)] == os.sep:
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000203 if len(dir) > len(longest):
204 longest = dir
205
Guido van Rossumb427c002003-10-10 23:02:01 +0000206 if longest:
207 base = path[len(longest) + 1:]
208 else:
209 base = path
Georg Brandl120d6332010-08-01 14:38:17 +0000210 # the drive letter is never part of the module name
211 drive, base = os.path.splitdrive(base)
Guido van Rossumbbca8da2004-02-19 19:16:50 +0000212 base = base.replace(os.sep, ".")
213 if os.altsep:
214 base = base.replace(os.altsep, ".")
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000215 filename, ext = os.path.splitext(base)
Georg Brandl120d6332010-08-01 14:38:17 +0000216 return filename.lstrip(".")
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000217
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000218class CoverageResults:
219 def __init__(self, counts=None, calledfuncs=None, infile=None,
Skip Montanarocafc8112004-04-07 15:46:05 +0000220 callers=None, outfile=None):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000221 self.counts = counts
222 if self.counts is None:
223 self.counts = {}
224 self.counter = self.counts.copy() # map (filename, lineno) to count
225 self.calledfuncs = calledfuncs
226 if self.calledfuncs is None:
227 self.calledfuncs = {}
228 self.calledfuncs = self.calledfuncs.copy()
Skip Montanarocafc8112004-04-07 15:46:05 +0000229 self.callers = callers
230 if self.callers is None:
231 self.callers = {}
232 self.callers = self.callers.copy()
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000233 self.infile = infile
234 self.outfile = outfile
235 if self.infile:
Jeremy Hyltond7ce86d2003-07-07 16:08:47 +0000236 # Try to merge existing counts file.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000237 try:
Skip Montanarocafc8112004-04-07 15:46:05 +0000238 counts, calledfuncs, callers = \
239 pickle.load(open(self.infile, 'rb'))
240 self.update(self.__class__(counts, calledfuncs, callers))
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200241 except (OSError, EOFError, ValueError) as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000242 print(("Skipping counts file %r: %s"
243 % (self.infile, err)), file=sys.stderr)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000244
Georg Brandl33c28812009-04-01 23:07:29 +0000245 def is_ignored_filename(self, filename):
246 """Return True if the filename does not refer to a file
247 we want to have reported.
248 """
Brett Cannon9fe92d12012-04-10 21:05:53 -0400249 return filename.startswith('<') and filename.endswith('>')
Georg Brandl33c28812009-04-01 23:07:29 +0000250
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000251 def update(self, other):
252 """Merge in the data from another CoverageResults"""
253 counts = self.counts
254 calledfuncs = self.calledfuncs
Skip Montanarocafc8112004-04-07 15:46:05 +0000255 callers = self.callers
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000256 other_counts = other.counts
257 other_calledfuncs = other.calledfuncs
Skip Montanarocafc8112004-04-07 15:46:05 +0000258 other_callers = other.callers
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000259
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000260 for key in other_counts:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000261 counts[key] = counts.get(key, 0) + other_counts[key]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000262
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000263 for key in other_calledfuncs:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000264 calledfuncs[key] = 1
265
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000266 for key in other_callers:
Skip Montanarocafc8112004-04-07 15:46:05 +0000267 callers[key] = 1
268
Jeremy Hylton38732e12003-04-21 22:04:46 +0000269 def write_results(self, show_missing=True, summary=False, coverdir=None):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000270 """
271 @param coverdir
272 """
Skip Montanarocafc8112004-04-07 15:46:05 +0000273 if self.calledfuncs:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000274 print()
275 print("functions called:")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000276 calls = self.calledfuncs
Alexander Belopolsky533a1672010-07-20 19:55:18 +0000277 for filename, modulename, funcname in sorted(calls):
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000278 print(("filename: %s, modulename: %s, funcname: %s"
279 % (filename, modulename, funcname)))
Skip Montanarocafc8112004-04-07 15:46:05 +0000280
281 if self.callers:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000282 print()
283 print("calling relationships:")
Skip Montanarocafc8112004-04-07 15:46:05 +0000284 lastfile = lastcfile = ""
Georg Brandl33c28812009-04-01 23:07:29 +0000285 for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) \
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000286 in sorted(self.callers):
Skip Montanarocafc8112004-04-07 15:46:05 +0000287 if pfile != lastfile:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000288 print()
289 print("***", pfile, "***")
Skip Montanarocafc8112004-04-07 15:46:05 +0000290 lastfile = pfile
291 lastcfile = ""
292 if cfile != pfile and lastcfile != cfile:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000293 print(" -->", cfile)
Skip Montanarocafc8112004-04-07 15:46:05 +0000294 lastcfile = cfile
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000295 print(" %s.%s -> %s.%s" % (pmod, pfunc, cmod, cfunc))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000296
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000297 # turn the counts data ("(filename, lineno) = count") into something
298 # accessible on a per-file basis
299 per_file = {}
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000300 for filename, lineno in self.counts:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000301 lines_hit = per_file[filename] = per_file.get(filename, {})
302 lines_hit[lineno] = self.counts[(filename, lineno)]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000303
304 # accumulate summary info, if needed
305 sums = {}
306
Guido van Rossumcc2b0162007-02-11 06:12:03 +0000307 for filename, count in per_file.items():
Georg Brandl33c28812009-04-01 23:07:29 +0000308 if self.is_ignored_filename(filename):
Guido van Rossum0d3fb8a2007-11-26 23:23:18 +0000309 continue
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000310
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000311 if filename.endswith((".pyc", ".pyo")):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000312 filename = filename[:-1]
313
Jeremy Hylton38732e12003-04-21 22:04:46 +0000314 if coverdir is None:
315 dir = os.path.dirname(os.path.abspath(filename))
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000316 modulename = _modname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000317 else:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000318 dir = coverdir
319 if not os.path.exists(dir):
320 os.makedirs(dir)
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000321 modulename = _fullmodname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000322
323 # If desired, get a list of the line numbers which represent
324 # executable content (returned as a dict for better lookup speed)
325 if show_missing:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000326 lnotab = _find_executable_linenos(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000327 else:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000328 lnotab = {}
Alexander Belopolskyf026dae2014-06-29 17:44:05 -0400329 if lnotab:
330 source = linecache.getlines(filename)
331 coverpath = os.path.join(dir, modulename + ".cover")
332 with open(filename, 'rb') as fp:
333 encoding, _ = tokenize.detect_encoding(fp.readline)
334 n_hits, n_lines = self.write_results_file(coverpath, source,
335 lnotab, count, encoding)
336 if summary and n_lines:
337 percent = int(100 * n_hits / n_lines)
338 sums[modulename] = n_lines, percent, modulename, filename
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000339
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000340
341 if summary and sums:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000342 print("lines cov% module (path)")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000343 for m in sorted(sums):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000344 n_lines, percent, modulename, filename = sums[m]
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000345 print("%5d %3d%% %s (%s)" % sums[m])
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000346
347 if self.outfile:
348 # try and store counts and module info into self.outfile
349 try:
Skip Montanarocafc8112004-04-07 15:46:05 +0000350 pickle.dump((self.counts, self.calledfuncs, self.callers),
Jeremy Hyltond0e27052003-10-14 20:12:06 +0000351 open(self.outfile, 'wb'), 1)
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200352 except OSError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000353 print("Can't save counts files because %s" % err, file=sys.stderr)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000354
Victor Stinner64bc3b22010-11-07 15:47:36 +0000355 def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000356 """Return a coverage results file in path."""
357
358 try:
Victor Stinner64bc3b22010-11-07 15:47:36 +0000359 outfile = open(path, "w", encoding=encoding)
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200360 except OSError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000361 print(("trace: Could not open %r for writing: %s"
362 "- skipping" % (path, err)), file=sys.stderr)
Guido van Rossumbbca8da2004-02-19 19:16:50 +0000363 return 0, 0
Jeremy Hylton38732e12003-04-21 22:04:46 +0000364
365 n_lines = 0
366 n_hits = 0
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000367 for lineno, line in enumerate(lines, 1):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000368 # do the blank/comment match to try to mark more lines
369 # (help the reader find stuff that hasn't been covered)
370 if lineno in lines_hit:
371 outfile.write("%5d: " % lines_hit[lineno])
372 n_hits += 1
373 n_lines += 1
374 elif rx_blank.match(line):
Walter Dörwaldc1711722003-07-15 10:34:02 +0000375 outfile.write(" ")
Jeremy Hylton38732e12003-04-21 22:04:46 +0000376 else:
377 # lines preceded by no marks weren't hit
378 # Highlight them if so indicated, unless the line contains
379 # #pragma: NO COVER
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000380 if lineno in lnotab and not PRAGMA_NOCOVER in line:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000381 outfile.write(">>>>>> ")
Jeremy Hylton546e34b2003-06-26 14:56:17 +0000382 n_lines += 1
Jeremy Hylton38732e12003-04-21 22:04:46 +0000383 else:
384 outfile.write(" ")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000385 outfile.write(line.expandtabs(8))
Jeremy Hylton38732e12003-04-21 22:04:46 +0000386 outfile.close()
387
388 return n_hits, n_lines
389
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000390def _find_lines_from_code(code, strs):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000391 """Return dict where keys are lines in the line number table."""
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000392 linenos = {}
393
Alexander Belopolskyff09ce22010-09-24 18:03:12 +0000394 for _, lineno in dis.findlinestarts(code):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000395 if lineno not in strs:
396 linenos[lineno] = 1
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000397
398 return linenos
399
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000400def _find_lines(code, strs):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000401 """Return lineno dict for all code objects reachable from code."""
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000402 # get all of the lineno information from the code of this scope level
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000403 linenos = _find_lines_from_code(code, strs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000404
405 # and check the constants for references to other code objects
406 for c in code.co_consts:
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000407 if inspect.iscode(c):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000408 # find another code object, so recurse into it
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000409 linenos.update(_find_lines(c, strs))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000410 return linenos
411
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000412def _find_strings(filename, encoding=None):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000413 """Return a dict of possible docstring positions.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000414
Jeremy Hylton38732e12003-04-21 22:04:46 +0000415 The dict maps line numbers to strings. There is an entry for
416 line that contains only a string or a part of a triple-quoted
417 string.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000418 """
Jeremy Hylton38732e12003-04-21 22:04:46 +0000419 d = {}
420 # If the first token is a string, then it's the module docstring.
421 # Add this special case so that the test in the loop passes.
422 prev_ttype = token.INDENT
Benjamin Petersonb2fda232010-10-30 23:51:34 +0000423 with open(filename, encoding=encoding) as f:
424 tok = tokenize.generate_tokens(f.readline)
425 for ttype, tstr, start, end, line in tok:
426 if ttype == token.STRING:
427 if prev_ttype == token.INDENT:
428 sline, scol = start
429 eline, ecol = end
430 for i in range(sline, eline + 1):
431 d[i] = 1
432 prev_ttype = ttype
Jeremy Hylton38732e12003-04-21 22:04:46 +0000433 return d
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000434
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000435def _find_executable_linenos(filename):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000436 """Return dict where keys are line numbers in the line number table."""
Jeremy Hylton38732e12003-04-21 22:04:46 +0000437 try:
Victor Stinner58c07522010-11-09 01:08:59 +0000438 with tokenize.open(filename) as f:
Benjamin Petersonb2fda232010-10-30 23:51:34 +0000439 prog = f.read()
Victor Stinner58c07522010-11-09 01:08:59 +0000440 encoding = f.encoding
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200441 except OSError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000442 print(("Not printing coverage data for %r: %s"
443 % (filename, err)), file=sys.stderr)
Jeremy Hylton38732e12003-04-21 22:04:46 +0000444 return {}
445 code = compile(prog, filename, "exec")
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000446 strs = _find_strings(filename, encoding)
447 return _find_lines(code, strs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000448
449class Trace:
Skip Montanarocafc8112004-04-07 15:46:05 +0000450 def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0,
Christian Heimes380f7f22008-02-28 11:19:05 +0000451 ignoremods=(), ignoredirs=(), infile=None, outfile=None,
452 timing=False):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000453 """
454 @param count true iff it should count number of times each
Tim Petersf2715e02003-02-19 02:35:07 +0000455 line is executed
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000456 @param trace true iff it should print out each line that is
Tim Petersf2715e02003-02-19 02:35:07 +0000457 being counted
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000458 @param countfuncs true iff it should just output a list of
459 (filename, modulename, funcname,) for functions
460 that were called at least once; This overrides
Tim Petersf2715e02003-02-19 02:35:07 +0000461 `count' and `trace'
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000462 @param ignoremods a list of the names of modules to ignore
463 @param ignoredirs a list of the names of directories to ignore
Tim Petersf2715e02003-02-19 02:35:07 +0000464 all of the (recursive) contents of
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000465 @param infile file from which to read stored counts to be
Tim Petersf2715e02003-02-19 02:35:07 +0000466 added into the results
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000467 @param outfile file in which to write the results
Christian Heimes380f7f22008-02-28 11:19:05 +0000468 @param timing true iff timing information be displayed
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000469 """
470 self.infile = infile
471 self.outfile = outfile
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000472 self.ignore = _Ignore(ignoremods, ignoredirs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000473 self.counts = {} # keys are (filename, linenumber)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000474 self.pathtobasename = {} # for memoizing os.path.basename
475 self.donothing = 0
476 self.trace = trace
477 self._calledfuncs = {}
Skip Montanarocafc8112004-04-07 15:46:05 +0000478 self._callers = {}
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000479 self._caller_cache = {}
Christian Heimes380f7f22008-02-28 11:19:05 +0000480 self.start_time = None
481 if timing:
Victor Stinner949d8c92012-05-30 13:30:32 +0200482 self.start_time = _time()
Skip Montanarocafc8112004-04-07 15:46:05 +0000483 if countcallers:
484 self.globaltrace = self.globaltrace_trackcallers
485 elif countfuncs:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000486 self.globaltrace = self.globaltrace_countfuncs
487 elif trace and count:
488 self.globaltrace = self.globaltrace_lt
489 self.localtrace = self.localtrace_trace_and_count
490 elif trace:
491 self.globaltrace = self.globaltrace_lt
492 self.localtrace = self.localtrace_trace
493 elif count:
494 self.globaltrace = self.globaltrace_lt
495 self.localtrace = self.localtrace_count
496 else:
497 # Ahem -- do nothing? Okay.
498 self.donothing = 1
499
500 def run(self, cmd):
501 import __main__
502 dict = __main__.__dict__
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000503 self.runctx(cmd, dict, dict)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000504
505 def runctx(self, cmd, globals=None, locals=None):
506 if globals is None: globals = {}
507 if locals is None: locals = {}
508 if not self.donothing:
Alexander Belopolsky25b57412010-11-06 01:31:16 +0000509 _settrace(self.globaltrace)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000510 try:
Georg Brandl7cae87c2006-09-06 06:51:57 +0000511 exec(cmd, globals, locals)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000512 finally:
513 if not self.donothing:
Alexander Belopolsky25b57412010-11-06 01:31:16 +0000514 _unsettrace()
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000515
516 def runfunc(self, func, *args, **kw):
517 result = None
518 if not self.donothing:
519 sys.settrace(self.globaltrace)
520 try:
Guido van Rossum68468eb2003-02-27 20:14:51 +0000521 result = func(*args, **kw)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000522 finally:
523 if not self.donothing:
524 sys.settrace(None)
525 return result
526
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000527 def file_module_function_of(self, frame):
528 code = frame.f_code
529 filename = code.co_filename
530 if filename:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000531 modulename = _modname(filename)
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000532 else:
533 modulename = None
534
535 funcname = code.co_name
536 clsname = None
537 if code in self._caller_cache:
538 if self._caller_cache[code] is not None:
539 clsname = self._caller_cache[code]
540 else:
541 self._caller_cache[code] = None
542 ## use of gc.get_referrers() was suggested by Michael Hudson
543 # all functions which refer to this code object
544 funcs = [f for f in gc.get_referrers(code)
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000545 if inspect.isfunction(f)]
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000546 # require len(func) == 1 to avoid ambiguity caused by calls to
547 # new.function(): "In the face of ambiguity, refuse the
548 # temptation to guess."
549 if len(funcs) == 1:
550 dicts = [d for d in gc.get_referrers(funcs[0])
551 if isinstance(d, dict)]
552 if len(dicts) == 1:
553 classes = [c for c in gc.get_referrers(dicts[0])
554 if hasattr(c, "__bases__")]
555 if len(classes) == 1:
556 # ditto for new.classobj()
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000557 clsname = classes[0].__name__
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000558 # cache the result - assumption is that new.* is
559 # not called later to disturb this relationship
560 # _caller_cache could be flushed if functions in
561 # the new module get called.
562 self._caller_cache[code] = clsname
563 if clsname is not None:
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000564 funcname = "%s.%s" % (clsname, funcname)
565
566 return filename, modulename, funcname
567
Skip Montanarocafc8112004-04-07 15:46:05 +0000568 def globaltrace_trackcallers(self, frame, why, arg):
569 """Handler for call events.
570
571 Adds information about who called who to the self._callers dict.
572 """
573 if why == 'call':
574 # XXX Should do a better job of identifying methods
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000575 this_func = self.file_module_function_of(frame)
576 parent_func = self.file_module_function_of(frame.f_back)
Skip Montanarocafc8112004-04-07 15:46:05 +0000577 self._callers[(parent_func, this_func)] = 1
578
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000579 def globaltrace_countfuncs(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000580 """Handler for call events.
Tim Peters0eadaac2003-04-24 16:02:54 +0000581
Jeremy Hylton38732e12003-04-21 22:04:46 +0000582 Adds (filename, modulename, funcname) to the self._calledfuncs dict.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000583 """
584 if why == 'call':
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000585 this_func = self.file_module_function_of(frame)
586 self._calledfuncs[this_func] = 1
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000587
588 def globaltrace_lt(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000589 """Handler for call events.
590
591 If the code block being entered is to be ignored, returns `None',
592 else returns self.localtrace.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000593 """
594 if why == 'call':
Jeremy Hylton38732e12003-04-21 22:04:46 +0000595 code = frame.f_code
Thomas Wouterscf297e42007-02-23 15:07:44 +0000596 filename = frame.f_globals.get('__file__', None)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000597 if filename:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000598 # XXX _modname() doesn't work right for packages, so
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000599 # the ignore support won't work right for packages
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000600 modulename = _modname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000601 if modulename is not None:
602 ignore_it = self.ignore.names(filename, modulename)
603 if not ignore_it:
604 if self.trace:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000605 print((" --- modulename: %s, funcname: %s"
606 % (modulename, code.co_name)))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000607 return self.localtrace
608 else:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000609 return None
610
611 def localtrace_trace_and_count(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000612 if why == "line":
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000613 # record the file name and line number of every trace
Jeremy Hylton38732e12003-04-21 22:04:46 +0000614 filename = frame.f_code.co_filename
615 lineno = frame.f_lineno
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000616 key = filename, lineno
617 self.counts[key] = self.counts.get(key, 0) + 1
Tim Petersf2715e02003-02-19 02:35:07 +0000618
Christian Heimes380f7f22008-02-28 11:19:05 +0000619 if self.start_time:
Victor Stinner949d8c92012-05-30 13:30:32 +0200620 print('%.2f' % (_time() - self.start_time), end=' ')
Jeremy Hylton38732e12003-04-21 22:04:46 +0000621 bname = os.path.basename(filename)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000622 print("%s(%d): %s" % (bname, lineno,
Georg Brandldc50c692010-08-02 12:40:22 +0000623 linecache.getline(filename, lineno)), end='')
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000624 return self.localtrace
625
626 def localtrace_trace(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000627 if why == "line":
628 # record the file name and line number of every trace
629 filename = frame.f_code.co_filename
630 lineno = frame.f_lineno
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000631
Christian Heimes380f7f22008-02-28 11:19:05 +0000632 if self.start_time:
Victor Stinner949d8c92012-05-30 13:30:32 +0200633 print('%.2f' % (_time() - self.start_time), end=' ')
Jeremy Hylton38732e12003-04-21 22:04:46 +0000634 bname = os.path.basename(filename)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000635 print("%s(%d): %s" % (bname, lineno,
Georg Brandldc50c692010-08-02 12:40:22 +0000636 linecache.getline(filename, lineno)), end='')
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000637 return self.localtrace
638
639 def localtrace_count(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000640 if why == "line":
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000641 filename = frame.f_code.co_filename
642 lineno = frame.f_lineno
643 key = filename, lineno
644 self.counts[key] = self.counts.get(key, 0) + 1
645 return self.localtrace
646
647 def results(self):
648 return CoverageResults(self.counts, infile=self.infile,
649 outfile=self.outfile,
Skip Montanarocafc8112004-04-07 15:46:05 +0000650 calledfuncs=self._calledfuncs,
651 callers=self._callers)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000652
653def _err_exit(msg):
654 sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
655 sys.exit(1)
656
657def main(argv=None):
658 import getopt
659
660 if argv is None:
661 argv = sys.argv
662 try:
Christian Heimes380f7f22008-02-28 11:19:05 +0000663 opts, prog_argv = getopt.getopt(argv[1:], "tcrRf:d:msC:lTg",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000664 ["help", "version", "trace", "count",
665 "report", "no-report", "summary",
666 "file=", "missing",
667 "ignore-module=", "ignore-dir=",
Skip Montanarocafc8112004-04-07 15:46:05 +0000668 "coverdir=", "listfuncs",
Christian Heimes380f7f22008-02-28 11:19:05 +0000669 "trackcalls", "timing"])
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000670
Guido van Rossumb940e112007-01-10 16:19:56 +0000671 except getopt.error as msg:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000672 sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
673 sys.stderr.write("Try `%s --help' for more information\n"
674 % sys.argv[0])
675 sys.exit(1)
676
677 trace = 0
678 count = 0
679 report = 0
680 no_report = 0
681 counts_file = None
682 missing = 0
683 ignore_modules = []
684 ignore_dirs = []
685 coverdir = None
686 summary = 0
687 listfuncs = False
Skip Montanarocafc8112004-04-07 15:46:05 +0000688 countcallers = False
Christian Heimes380f7f22008-02-28 11:19:05 +0000689 timing = False
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000690
691 for opt, val in opts:
692 if opt == "--help":
Éric Araujoe7d36fe2011-04-17 16:48:52 +0200693 _usage(sys.stdout)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000694 sys.exit(0)
695
696 if opt == "--version":
697 sys.stdout.write("trace 2.0\n")
698 sys.exit(0)
699
Skip Montanarocafc8112004-04-07 15:46:05 +0000700 if opt == "-T" or opt == "--trackcalls":
701 countcallers = True
702 continue
703
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000704 if opt == "-l" or opt == "--listfuncs":
705 listfuncs = True
706 continue
707
Christian Heimes380f7f22008-02-28 11:19:05 +0000708 if opt == "-g" or opt == "--timing":
709 timing = True
710 continue
711
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000712 if opt == "-t" or opt == "--trace":
713 trace = 1
714 continue
715
716 if opt == "-c" or opt == "--count":
717 count = 1
718 continue
719
720 if opt == "-r" or opt == "--report":
721 report = 1
722 continue
723
724 if opt == "-R" or opt == "--no-report":
725 no_report = 1
726 continue
727
728 if opt == "-f" or opt == "--file":
729 counts_file = val
730 continue
731
732 if opt == "-m" or opt == "--missing":
733 missing = 1
734 continue
735
736 if opt == "-C" or opt == "--coverdir":
737 coverdir = val
738 continue
739
740 if opt == "-s" or opt == "--summary":
741 summary = 1
742 continue
743
744 if opt == "--ignore-module":
Georg Brandlfceab5a2008-01-19 20:08:23 +0000745 for mod in val.split(","):
746 ignore_modules.append(mod.strip())
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000747 continue
748
749 if opt == "--ignore-dir":
750 for s in val.split(os.pathsep):
751 s = os.path.expandvars(s)
752 # should I also call expanduser? (after all, could use $HOME)
753
754 s = s.replace("$prefix",
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100755 os.path.join(sys.base_prefix, "lib",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000756 "python" + sys.version[:3]))
757 s = s.replace("$exec_prefix",
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100758 os.path.join(sys.base_exec_prefix, "lib",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000759 "python" + sys.version[:3]))
760 s = os.path.normpath(s)
761 ignore_dirs.append(s)
762 continue
763
764 assert 0, "Should never get here"
765
766 if listfuncs and (count or trace):
767 _err_exit("cannot specify both --listfuncs and (--trace or --count)")
768
Skip Montanarocafc8112004-04-07 15:46:05 +0000769 if not (count or trace or report or listfuncs or countcallers):
770 _err_exit("must specify one of --trace, --count, --report, "
771 "--listfuncs, or --trackcalls")
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000772
773 if report and no_report:
774 _err_exit("cannot specify both --report and --no-report")
775
776 if report and not counts_file:
777 _err_exit("--report requires a --file")
778
779 if no_report and len(prog_argv) == 0:
780 _err_exit("missing name of file to run")
781
782 # everything is ready
783 if report:
784 results = CoverageResults(infile=counts_file, outfile=counts_file)
785 results.write_results(missing, summary=summary, coverdir=coverdir)
786 else:
787 sys.argv = prog_argv
788 progname = prog_argv[0]
789 sys.path[0] = os.path.split(progname)[0]
790
791 t = Trace(count, trace, countfuncs=listfuncs,
Skip Montanarocafc8112004-04-07 15:46:05 +0000792 countcallers=countcallers, ignoremods=ignore_modules,
793 ignoredirs=ignore_dirs, infile=counts_file,
Christian Heimes380f7f22008-02-28 11:19:05 +0000794 outfile=counts_file, timing=timing)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000795 try:
Alexander Belopolsky3f8ecab2010-07-21 17:43:42 +0000796 with open(progname) as fp:
797 code = compile(fp.read(), progname, 'exec')
Georg Brandl8f9f4662010-08-01 08:35:29 +0000798 # try to emulate __main__ namespace as much as possible
799 globs = {
800 '__file__': progname,
801 '__name__': '__main__',
802 '__package__': None,
803 '__cached__': None,
804 }
805 t.runctx(code, globs, globs)
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200806 except OSError as err:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000807 _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000808 except SystemExit:
809 pass
810
811 results = t.results()
812
813 if not no_report:
814 results.write_results(missing, summary=summary, coverdir=coverdir)
815
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000816# Deprecated API
817def usage(outfile):
818 _warn("The trace.usage() function is deprecated",
819 DeprecationWarning, 2)
820 _usage(outfile)
821
822class Ignore(_Ignore):
823 def __init__(self, modules=None, dirs=None):
824 _warn("The class trace.Ignore is deprecated",
825 DeprecationWarning, 2)
826 _Ignore.__init__(self, modules, dirs)
827
828def modname(path):
829 _warn("The trace.modname() function is deprecated",
830 DeprecationWarning, 2)
831 return _modname(path)
832
833def fullmodname(path):
834 _warn("The trace.fullmodname() function is deprecated",
835 DeprecationWarning, 2)
836 return _fullmodname(path)
837
838def find_lines_from_code(code, strs):
839 _warn("The trace.find_lines_from_code() function is deprecated",
840 DeprecationWarning, 2)
841 return _find_lines_from_code(code, strs)
842
843def find_lines(code, strs):
844 _warn("The trace.find_lines() function is deprecated",
845 DeprecationWarning, 2)
846 return _find_lines(code, strs)
847
848def find_strings(filename, encoding=None):
849 _warn("The trace.find_strings() function is deprecated",
850 DeprecationWarning, 2)
851 return _find_strings(filename, encoding=None)
852
853def find_executable_linenos(filename):
854 _warn("The trace.find_executable_linenos() function is deprecated",
855 DeprecationWarning, 2)
856 return _find_executable_linenos(filename)
857
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000858if __name__=='__main__':
859 main()