blob: 41c2f5f69ae87d74764bc4b55a8f2b073eb257a2 [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']
Georg Brandl33c28812009-04-01 23:07:29 +000051import io
Jeremy Hylton38732e12003-04-21 22:04:46 +000052import linecache
Jeremy Hylton38732e12003-04-21 22:04:46 +000053import os
54import re
55import sys
Christian Heimes380f7f22008-02-28 11:19:05 +000056import time
Jeremy Hylton38732e12003-04-21 22:04:46 +000057import token
58import tokenize
Alexander Belopolsky4d770172010-09-13 18:14:34 +000059import inspect
Skip Montanaro5bfd9842004-04-10 16:29:58 +000060import gc
Alexander Belopolskyff09ce22010-09-24 18:03:12 +000061import dis
Guido van Rossum99603b02007-07-20 00:22:32 +000062import pickle
Alexander Belopolsky44454af2010-11-20 18:21:07 +000063from warnings import warn as _warn
Victor Stinner949d8c92012-05-30 13:30:32 +020064try:
65 from time import monotonic as _time
66except ImportError:
67 from time import time as _time
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000068
Alexander Belopolsky25b57412010-11-06 01:31:16 +000069try:
70 import threading
71except ImportError:
72 _settrace = sys.settrace
73
74 def _unsettrace():
75 sys.settrace(None)
76else:
77 def _settrace(func):
78 threading.settrace(func)
79 sys.settrace(func)
80
81 def _unsettrace():
82 sys.settrace(None)
83 threading.settrace(None)
84
Alexander Belopolsky44454af2010-11-20 18:21:07 +000085def _usage(outfile):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +000086 outfile.write("""Usage: %s [OPTIONS] <file> [ARGS]
87
88Meta-options:
89--help Display this help then exit.
90--version Output version information then exit.
91
92Otherwise, exactly one of the following three options must be given:
93-t, --trace Print each line to sys.stdout before it is executed.
94-c, --count Count the number of times each line is executed
95 and write the counts to <module>.cover for each
96 module executed, in the module's directory.
97 See also `--coverdir', `--file', `--no-report' below.
Skip Montanaroa7b8ac62003-06-27 19:09:33 +000098-l, --listfuncs Keep track of which functions are executed at least
Fred Drake01c623b2003-06-27 19:22:11 +000099 once and write the results to sys.stdout after the
Skip Montanaroa7b8ac62003-06-27 19:09:33 +0000100 program exits.
Skip Montanarocafc8112004-04-07 15:46:05 +0000101-T, --trackcalls Keep track of caller/called pairs and write the
102 results to sys.stdout after the program exits.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000103-r, --report Generate a report from a counts file; do not execute
104 any code. `--file' must specify the results file to
105 read, which must have been created in a previous run
106 with `--count --file=FILE'.
107
108Modifiers:
109-f, --file=<file> File to accumulate counts over several runs.
110-R, --no-report Do not generate the coverage report files.
111 Useful if you want to accumulate over several runs.
112-C, --coverdir=<dir> Directory where the report files. The coverage
113 report for <package>.<module> is written to file
114 <dir>/<package>/<module>.cover.
115-m, --missing Annotate executable lines that were not executed
116 with '>>>>>> '.
117-s, --summary Write a brief summary on stdout for each file.
118 (Can only be used with --count or --report.)
Christian Heimes380f7f22008-02-28 11:19:05 +0000119-g, --timing Prefix each line with the time since the program started.
120 Only used while tracing.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000121
122Filters, may be repeated multiple times:
Georg Brandlfceab5a2008-01-19 20:08:23 +0000123--ignore-module=<mod> Ignore the given module(s) and its submodules
124 (if it is a package). Accepts comma separated
125 list of module names
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000126--ignore-dir=<dir> Ignore files in the given directory (multiple
127 directories can be joined by os.pathsep).
128""" % sys.argv[0])
129
Jeremy Hylton38732e12003-04-21 22:04:46 +0000130PRAGMA_NOCOVER = "#pragma NO COVER"
131
132# Simple rx to find lines with no code.
133rx_blank = re.compile(r'^\s*(#.*)?$')
134
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000135class _Ignore:
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000136 def __init__(self, modules=None, dirs=None):
137 self._mods = set() if not modules else set(modules)
138 self._dirs = [] if not dirs else [os.path.normpath(d)
139 for d in dirs]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000140 self._ignore = { '<string>': 1 }
141
142 def names(self, filename, modulename):
Guido van Rossume2b70bc2006-08-18 22:13:04 +0000143 if modulename in self._ignore:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000144 return self._ignore[modulename]
145
146 # haven't seen this one before, so see if the module name is
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000147 # on the ignore list.
148 if modulename in self._mods: # Identical names, so ignore
149 self._ignore[modulename] = 1
150 return 1
151
152 # check if the module is a proper submodule of something on
153 # the ignore list
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000154 for mod in self._mods:
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000155 # Need to take some care since ignoring
156 # "cmp" mustn't mean ignoring "cmpcache" but ignoring
157 # "Spam" must also mean ignoring "Spam.Eggs".
158 if modulename.startswith(mod + '.'):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000159 self._ignore[modulename] = 1
160 return 1
161
Alexander Belopolsky6672ea92010-11-08 18:32:40 +0000162 # Now check that filename isn't in one of the directories
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000163 if filename is None:
164 # must be a built-in, so we must ignore
165 self._ignore[modulename] = 1
166 return 1
167
168 # Ignore a file when it contains one of the ignorable paths
169 for d in self._dirs:
170 # The '+ os.sep' is to ensure that d is a parent directory,
171 # as compared to cases like:
172 # d = "/usr/local"
173 # filename = "/usr/local.py"
174 # or
175 # d = "/usr/local.py"
176 # filename = "/usr/local.py"
177 if filename.startswith(d + os.sep):
178 self._ignore[modulename] = 1
179 return 1
180
181 # Tried the different ways, so we don't ignore this module
182 self._ignore[modulename] = 0
183 return 0
184
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000185def _modname(path):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000186 """Return a plausible module name for the patch."""
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000187
Jeremy Hylton38732e12003-04-21 22:04:46 +0000188 base = os.path.basename(path)
189 filename, ext = os.path.splitext(base)
190 return filename
191
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000192def _fullmodname(path):
Jeremy Hyltonc8c8b942003-04-22 15:35:51 +0000193 """Return a plausible module name for the path."""
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000194
195 # If the file 'path' is part of a package, then the filename isn't
196 # enough to uniquely identify it. Try to do the right thing by
197 # looking in sys.path for the longest matching prefix. We'll
198 # assume that the rest is the package name.
199
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000200 comparepath = os.path.normcase(path)
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000201 longest = ""
202 for dir in sys.path:
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000203 dir = os.path.normcase(dir)
204 if comparepath.startswith(dir) and comparepath[len(dir)] == os.sep:
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000205 if len(dir) > len(longest):
206 longest = dir
207
Guido van Rossumb427c002003-10-10 23:02:01 +0000208 if longest:
209 base = path[len(longest) + 1:]
210 else:
211 base = path
Georg Brandl120d6332010-08-01 14:38:17 +0000212 # the drive letter is never part of the module name
213 drive, base = os.path.splitdrive(base)
Guido van Rossumbbca8da2004-02-19 19:16:50 +0000214 base = base.replace(os.sep, ".")
215 if os.altsep:
216 base = base.replace(os.altsep, ".")
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000217 filename, ext = os.path.splitext(base)
Georg Brandl120d6332010-08-01 14:38:17 +0000218 return filename.lstrip(".")
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000219
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000220class CoverageResults:
221 def __init__(self, counts=None, calledfuncs=None, infile=None,
Skip Montanarocafc8112004-04-07 15:46:05 +0000222 callers=None, outfile=None):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000223 self.counts = counts
224 if self.counts is None:
225 self.counts = {}
226 self.counter = self.counts.copy() # map (filename, lineno) to count
227 self.calledfuncs = calledfuncs
228 if self.calledfuncs is None:
229 self.calledfuncs = {}
230 self.calledfuncs = self.calledfuncs.copy()
Skip Montanarocafc8112004-04-07 15:46:05 +0000231 self.callers = callers
232 if self.callers is None:
233 self.callers = {}
234 self.callers = self.callers.copy()
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000235 self.infile = infile
236 self.outfile = outfile
237 if self.infile:
Jeremy Hyltond7ce86d2003-07-07 16:08:47 +0000238 # Try to merge existing counts file.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000239 try:
Skip Montanarocafc8112004-04-07 15:46:05 +0000240 counts, calledfuncs, callers = \
241 pickle.load(open(self.infile, 'rb'))
242 self.update(self.__class__(counts, calledfuncs, callers))
Guido van Rossumb940e112007-01-10 16:19:56 +0000243 except (IOError, EOFError, ValueError) as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000244 print(("Skipping counts file %r: %s"
245 % (self.infile, err)), file=sys.stderr)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000246
Georg Brandl33c28812009-04-01 23:07:29 +0000247 def is_ignored_filename(self, filename):
248 """Return True if the filename does not refer to a file
249 we want to have reported.
250 """
Brett Cannon9fe92d12012-04-10 21:05:53 -0400251 return filename.startswith('<') and filename.endswith('>')
Georg Brandl33c28812009-04-01 23:07:29 +0000252
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000253 def update(self, other):
254 """Merge in the data from another CoverageResults"""
255 counts = self.counts
256 calledfuncs = self.calledfuncs
Skip Montanarocafc8112004-04-07 15:46:05 +0000257 callers = self.callers
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000258 other_counts = other.counts
259 other_calledfuncs = other.calledfuncs
Skip Montanarocafc8112004-04-07 15:46:05 +0000260 other_callers = other.callers
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000261
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000262 for key in other_counts:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000263 counts[key] = counts.get(key, 0) + other_counts[key]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000264
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000265 for key in other_calledfuncs:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000266 calledfuncs[key] = 1
267
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000268 for key in other_callers:
Skip Montanarocafc8112004-04-07 15:46:05 +0000269 callers[key] = 1
270
Jeremy Hylton38732e12003-04-21 22:04:46 +0000271 def write_results(self, show_missing=True, summary=False, coverdir=None):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000272 """
273 @param coverdir
274 """
Skip Montanarocafc8112004-04-07 15:46:05 +0000275 if self.calledfuncs:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000276 print()
277 print("functions called:")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000278 calls = self.calledfuncs
Alexander Belopolsky533a1672010-07-20 19:55:18 +0000279 for filename, modulename, funcname in sorted(calls):
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000280 print(("filename: %s, modulename: %s, funcname: %s"
281 % (filename, modulename, funcname)))
Skip Montanarocafc8112004-04-07 15:46:05 +0000282
283 if self.callers:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000284 print()
285 print("calling relationships:")
Skip Montanarocafc8112004-04-07 15:46:05 +0000286 lastfile = lastcfile = ""
Georg Brandl33c28812009-04-01 23:07:29 +0000287 for ((pfile, pmod, pfunc), (cfile, cmod, cfunc)) \
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000288 in sorted(self.callers):
Skip Montanarocafc8112004-04-07 15:46:05 +0000289 if pfile != lastfile:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000290 print()
291 print("***", pfile, "***")
Skip Montanarocafc8112004-04-07 15:46:05 +0000292 lastfile = pfile
293 lastcfile = ""
294 if cfile != pfile and lastcfile != cfile:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000295 print(" -->", cfile)
Skip Montanarocafc8112004-04-07 15:46:05 +0000296 lastcfile = cfile
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000297 print(" %s.%s -> %s.%s" % (pmod, pfunc, cmod, cfunc))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000298
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000299 # turn the counts data ("(filename, lineno) = count") into something
300 # accessible on a per-file basis
301 per_file = {}
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000302 for filename, lineno in self.counts:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000303 lines_hit = per_file[filename] = per_file.get(filename, {})
304 lines_hit[lineno] = self.counts[(filename, lineno)]
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000305
306 # accumulate summary info, if needed
307 sums = {}
308
Guido van Rossumcc2b0162007-02-11 06:12:03 +0000309 for filename, count in per_file.items():
Georg Brandl33c28812009-04-01 23:07:29 +0000310 if self.is_ignored_filename(filename):
Guido van Rossum0d3fb8a2007-11-26 23:23:18 +0000311 continue
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000312
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000313 if filename.endswith((".pyc", ".pyo")):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000314 filename = filename[:-1]
315
Jeremy Hylton38732e12003-04-21 22:04:46 +0000316 if coverdir is None:
317 dir = os.path.dirname(os.path.abspath(filename))
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000318 modulename = _modname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000319 else:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000320 dir = coverdir
321 if not os.path.exists(dir):
322 os.makedirs(dir)
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000323 modulename = _fullmodname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000324
325 # If desired, get a list of the line numbers which represent
326 # executable content (returned as a dict for better lookup speed)
327 if show_missing:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000328 lnotab = _find_executable_linenos(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000329 else:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000330 lnotab = {}
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000331
Jeremy Hylton38732e12003-04-21 22:04:46 +0000332 source = linecache.getlines(filename)
333 coverpath = os.path.join(dir, modulename + ".cover")
Victor Stinner64bc3b22010-11-07 15:47:36 +0000334 with open(filename, 'rb') as fp:
335 encoding, _ = tokenize.detect_encoding(fp.readline)
Jeremy Hylton38732e12003-04-21 22:04:46 +0000336 n_hits, n_lines = self.write_results_file(coverpath, source,
Victor Stinner64bc3b22010-11-07 15:47:36 +0000337 lnotab, count, encoding)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000338 if summary and n_lines:
339 percent = int(100 * n_hits / n_lines)
340 sums[modulename] = n_lines, percent, modulename, filename
341
342 if summary and sums:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000343 print("lines cov% module (path)")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000344 for m in sorted(sums):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000345 n_lines, percent, modulename, filename = sums[m]
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000346 print("%5d %3d%% %s (%s)" % sums[m])
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000347
348 if self.outfile:
349 # try and store counts and module info into self.outfile
350 try:
Skip Montanarocafc8112004-04-07 15:46:05 +0000351 pickle.dump((self.counts, self.calledfuncs, self.callers),
Jeremy Hyltond0e27052003-10-14 20:12:06 +0000352 open(self.outfile, 'wb'), 1)
Guido van Rossumb940e112007-01-10 16:19:56 +0000353 except IOError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000354 print("Can't save counts files because %s" % err, file=sys.stderr)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000355
Victor Stinner64bc3b22010-11-07 15:47:36 +0000356 def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000357 """Return a coverage results file in path."""
358
359 try:
Victor Stinner64bc3b22010-11-07 15:47:36 +0000360 outfile = open(path, "w", encoding=encoding)
Guido van Rossumb940e112007-01-10 16:19:56 +0000361 except IOError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000362 print(("trace: Could not open %r for writing: %s"
363 "- skipping" % (path, err)), file=sys.stderr)
Guido van Rossumbbca8da2004-02-19 19:16:50 +0000364 return 0, 0
Jeremy Hylton38732e12003-04-21 22:04:46 +0000365
366 n_lines = 0
367 n_hits = 0
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000368 for lineno, line in enumerate(lines, 1):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000369 # do the blank/comment match to try to mark more lines
370 # (help the reader find stuff that hasn't been covered)
371 if lineno in lines_hit:
372 outfile.write("%5d: " % lines_hit[lineno])
373 n_hits += 1
374 n_lines += 1
375 elif rx_blank.match(line):
Walter Dörwaldc1711722003-07-15 10:34:02 +0000376 outfile.write(" ")
Jeremy Hylton38732e12003-04-21 22:04:46 +0000377 else:
378 # lines preceded by no marks weren't hit
379 # Highlight them if so indicated, unless the line contains
380 # #pragma: NO COVER
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000381 if lineno in lnotab and not PRAGMA_NOCOVER in line:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000382 outfile.write(">>>>>> ")
Jeremy Hylton546e34b2003-06-26 14:56:17 +0000383 n_lines += 1
Jeremy Hylton38732e12003-04-21 22:04:46 +0000384 else:
385 outfile.write(" ")
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000386 outfile.write(line.expandtabs(8))
Jeremy Hylton38732e12003-04-21 22:04:46 +0000387 outfile.close()
388
389 return n_hits, n_lines
390
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000391def _find_lines_from_code(code, strs):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000392 """Return dict where keys are lines in the line number table."""
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000393 linenos = {}
394
Alexander Belopolskyff09ce22010-09-24 18:03:12 +0000395 for _, lineno in dis.findlinestarts(code):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000396 if lineno not in strs:
397 linenos[lineno] = 1
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000398
399 return linenos
400
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000401def _find_lines(code, strs):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000402 """Return lineno dict for all code objects reachable from code."""
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000403 # get all of the lineno information from the code of this scope level
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000404 linenos = _find_lines_from_code(code, strs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000405
406 # and check the constants for references to other code objects
407 for c in code.co_consts:
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000408 if inspect.iscode(c):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000409 # find another code object, so recurse into it
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000410 linenos.update(_find_lines(c, strs))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000411 return linenos
412
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000413def _find_strings(filename, encoding=None):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000414 """Return a dict of possible docstring positions.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000415
Jeremy Hylton38732e12003-04-21 22:04:46 +0000416 The dict maps line numbers to strings. There is an entry for
417 line that contains only a string or a part of a triple-quoted
418 string.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000419 """
Jeremy Hylton38732e12003-04-21 22:04:46 +0000420 d = {}
421 # If the first token is a string, then it's the module docstring.
422 # Add this special case so that the test in the loop passes.
423 prev_ttype = token.INDENT
Benjamin Petersonb2fda232010-10-30 23:51:34 +0000424 with open(filename, encoding=encoding) as f:
425 tok = tokenize.generate_tokens(f.readline)
426 for ttype, tstr, start, end, line in tok:
427 if ttype == token.STRING:
428 if prev_ttype == token.INDENT:
429 sline, scol = start
430 eline, ecol = end
431 for i in range(sline, eline + 1):
432 d[i] = 1
433 prev_ttype = ttype
Jeremy Hylton38732e12003-04-21 22:04:46 +0000434 return d
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000435
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000436def _find_executable_linenos(filename):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000437 """Return dict where keys are line numbers in the line number table."""
Jeremy Hylton38732e12003-04-21 22:04:46 +0000438 try:
Victor Stinner58c07522010-11-09 01:08:59 +0000439 with tokenize.open(filename) as f:
Benjamin Petersonb2fda232010-10-30 23:51:34 +0000440 prog = f.read()
Victor Stinner58c07522010-11-09 01:08:59 +0000441 encoding = f.encoding
Guido van Rossumb940e112007-01-10 16:19:56 +0000442 except IOError as err:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000443 print(("Not printing coverage data for %r: %s"
444 % (filename, err)), file=sys.stderr)
Jeremy Hylton38732e12003-04-21 22:04:46 +0000445 return {}
446 code = compile(prog, filename, "exec")
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000447 strs = _find_strings(filename, encoding)
448 return _find_lines(code, strs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000449
450class Trace:
Skip Montanarocafc8112004-04-07 15:46:05 +0000451 def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0,
Christian Heimes380f7f22008-02-28 11:19:05 +0000452 ignoremods=(), ignoredirs=(), infile=None, outfile=None,
453 timing=False):
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000454 """
455 @param count true iff it should count number of times each
Tim Petersf2715e02003-02-19 02:35:07 +0000456 line is executed
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000457 @param trace true iff it should print out each line that is
Tim Petersf2715e02003-02-19 02:35:07 +0000458 being counted
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000459 @param countfuncs true iff it should just output a list of
460 (filename, modulename, funcname,) for functions
461 that were called at least once; This overrides
Tim Petersf2715e02003-02-19 02:35:07 +0000462 `count' and `trace'
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000463 @param ignoremods a list of the names of modules to ignore
464 @param ignoredirs a list of the names of directories to ignore
Tim Petersf2715e02003-02-19 02:35:07 +0000465 all of the (recursive) contents of
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000466 @param infile file from which to read stored counts to be
Tim Petersf2715e02003-02-19 02:35:07 +0000467 added into the results
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000468 @param outfile file in which to write the results
Christian Heimes380f7f22008-02-28 11:19:05 +0000469 @param timing true iff timing information be displayed
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000470 """
471 self.infile = infile
472 self.outfile = outfile
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000473 self.ignore = _Ignore(ignoremods, ignoredirs)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000474 self.counts = {} # keys are (filename, linenumber)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000475 self.pathtobasename = {} # for memoizing os.path.basename
476 self.donothing = 0
477 self.trace = trace
478 self._calledfuncs = {}
Skip Montanarocafc8112004-04-07 15:46:05 +0000479 self._callers = {}
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000480 self._caller_cache = {}
Christian Heimes380f7f22008-02-28 11:19:05 +0000481 self.start_time = None
482 if timing:
Victor Stinner949d8c92012-05-30 13:30:32 +0200483 self.start_time = _time()
Skip Montanarocafc8112004-04-07 15:46:05 +0000484 if countcallers:
485 self.globaltrace = self.globaltrace_trackcallers
486 elif countfuncs:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000487 self.globaltrace = self.globaltrace_countfuncs
488 elif trace and count:
489 self.globaltrace = self.globaltrace_lt
490 self.localtrace = self.localtrace_trace_and_count
491 elif trace:
492 self.globaltrace = self.globaltrace_lt
493 self.localtrace = self.localtrace_trace
494 elif count:
495 self.globaltrace = self.globaltrace_lt
496 self.localtrace = self.localtrace_count
497 else:
498 # Ahem -- do nothing? Okay.
499 self.donothing = 1
500
501 def run(self, cmd):
502 import __main__
503 dict = __main__.__dict__
Alexander Belopolsky0ae33612010-09-27 15:49:20 +0000504 self.runctx(cmd, dict, dict)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000505
506 def runctx(self, cmd, globals=None, locals=None):
507 if globals is None: globals = {}
508 if locals is None: locals = {}
509 if not self.donothing:
Alexander Belopolsky25b57412010-11-06 01:31:16 +0000510 _settrace(self.globaltrace)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000511 try:
Georg Brandl7cae87c2006-09-06 06:51:57 +0000512 exec(cmd, globals, locals)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000513 finally:
514 if not self.donothing:
Alexander Belopolsky25b57412010-11-06 01:31:16 +0000515 _unsettrace()
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000516
517 def runfunc(self, func, *args, **kw):
518 result = None
519 if not self.donothing:
520 sys.settrace(self.globaltrace)
521 try:
Guido van Rossum68468eb2003-02-27 20:14:51 +0000522 result = func(*args, **kw)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000523 finally:
524 if not self.donothing:
525 sys.settrace(None)
526 return result
527
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000528 def file_module_function_of(self, frame):
529 code = frame.f_code
530 filename = code.co_filename
531 if filename:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000532 modulename = _modname(filename)
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000533 else:
534 modulename = None
535
536 funcname = code.co_name
537 clsname = None
538 if code in self._caller_cache:
539 if self._caller_cache[code] is not None:
540 clsname = self._caller_cache[code]
541 else:
542 self._caller_cache[code] = None
543 ## use of gc.get_referrers() was suggested by Michael Hudson
544 # all functions which refer to this code object
545 funcs = [f for f in gc.get_referrers(code)
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000546 if inspect.isfunction(f)]
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000547 # require len(func) == 1 to avoid ambiguity caused by calls to
548 # new.function(): "In the face of ambiguity, refuse the
549 # temptation to guess."
550 if len(funcs) == 1:
551 dicts = [d for d in gc.get_referrers(funcs[0])
552 if isinstance(d, dict)]
553 if len(dicts) == 1:
554 classes = [c for c in gc.get_referrers(dicts[0])
555 if hasattr(c, "__bases__")]
556 if len(classes) == 1:
557 # ditto for new.classobj()
Alexander Belopolsky4d770172010-09-13 18:14:34 +0000558 clsname = classes[0].__name__
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000559 # cache the result - assumption is that new.* is
560 # not called later to disturb this relationship
561 # _caller_cache could be flushed if functions in
562 # the new module get called.
563 self._caller_cache[code] = clsname
564 if clsname is not None:
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000565 funcname = "%s.%s" % (clsname, funcname)
566
567 return filename, modulename, funcname
568
Skip Montanarocafc8112004-04-07 15:46:05 +0000569 def globaltrace_trackcallers(self, frame, why, arg):
570 """Handler for call events.
571
572 Adds information about who called who to the self._callers dict.
573 """
574 if why == 'call':
575 # XXX Should do a better job of identifying methods
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000576 this_func = self.file_module_function_of(frame)
577 parent_func = self.file_module_function_of(frame.f_back)
Skip Montanarocafc8112004-04-07 15:46:05 +0000578 self._callers[(parent_func, this_func)] = 1
579
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000580 def globaltrace_countfuncs(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000581 """Handler for call events.
Tim Peters0eadaac2003-04-24 16:02:54 +0000582
Jeremy Hylton38732e12003-04-21 22:04:46 +0000583 Adds (filename, modulename, funcname) to the self._calledfuncs dict.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000584 """
585 if why == 'call':
Skip Montanaro5bfd9842004-04-10 16:29:58 +0000586 this_func = self.file_module_function_of(frame)
587 self._calledfuncs[this_func] = 1
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000588
589 def globaltrace_lt(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000590 """Handler for call events.
591
592 If the code block being entered is to be ignored, returns `None',
593 else returns self.localtrace.
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000594 """
595 if why == 'call':
Jeremy Hylton38732e12003-04-21 22:04:46 +0000596 code = frame.f_code
Thomas Wouterscf297e42007-02-23 15:07:44 +0000597 filename = frame.f_globals.get('__file__', None)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000598 if filename:
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000599 # XXX _modname() doesn't work right for packages, so
Jeremy Hyltondfbfe732003-04-21 22:49:17 +0000600 # the ignore support won't work right for packages
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000601 modulename = _modname(filename)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000602 if modulename is not None:
603 ignore_it = self.ignore.names(filename, modulename)
604 if not ignore_it:
605 if self.trace:
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000606 print((" --- modulename: %s, funcname: %s"
607 % (modulename, code.co_name)))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000608 return self.localtrace
609 else:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000610 return None
611
612 def localtrace_trace_and_count(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000613 if why == "line":
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000614 # record the file name and line number of every trace
Jeremy Hylton38732e12003-04-21 22:04:46 +0000615 filename = frame.f_code.co_filename
616 lineno = frame.f_lineno
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000617 key = filename, lineno
618 self.counts[key] = self.counts.get(key, 0) + 1
Tim Petersf2715e02003-02-19 02:35:07 +0000619
Christian Heimes380f7f22008-02-28 11:19:05 +0000620 if self.start_time:
Victor Stinner949d8c92012-05-30 13:30:32 +0200621 print('%.2f' % (_time() - self.start_time), end=' ')
Jeremy Hylton38732e12003-04-21 22:04:46 +0000622 bname = os.path.basename(filename)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000623 print("%s(%d): %s" % (bname, lineno,
Georg Brandldc50c692010-08-02 12:40:22 +0000624 linecache.getline(filename, lineno)), end='')
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000625 return self.localtrace
626
627 def localtrace_trace(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000628 if why == "line":
629 # record the file name and line number of every trace
630 filename = frame.f_code.co_filename
631 lineno = frame.f_lineno
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000632
Christian Heimes380f7f22008-02-28 11:19:05 +0000633 if self.start_time:
Victor Stinner949d8c92012-05-30 13:30:32 +0200634 print('%.2f' % (_time() - self.start_time), end=' ')
Jeremy Hylton38732e12003-04-21 22:04:46 +0000635 bname = os.path.basename(filename)
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000636 print("%s(%d): %s" % (bname, lineno,
Georg Brandldc50c692010-08-02 12:40:22 +0000637 linecache.getline(filename, lineno)), end='')
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000638 return self.localtrace
639
640 def localtrace_count(self, frame, why, arg):
Jeremy Hylton38732e12003-04-21 22:04:46 +0000641 if why == "line":
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000642 filename = frame.f_code.co_filename
643 lineno = frame.f_lineno
644 key = filename, lineno
645 self.counts[key] = self.counts.get(key, 0) + 1
646 return self.localtrace
647
648 def results(self):
649 return CoverageResults(self.counts, infile=self.infile,
650 outfile=self.outfile,
Skip Montanarocafc8112004-04-07 15:46:05 +0000651 calledfuncs=self._calledfuncs,
652 callers=self._callers)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000653
654def _err_exit(msg):
655 sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
656 sys.exit(1)
657
658def main(argv=None):
659 import getopt
660
661 if argv is None:
662 argv = sys.argv
663 try:
Christian Heimes380f7f22008-02-28 11:19:05 +0000664 opts, prog_argv = getopt.getopt(argv[1:], "tcrRf:d:msC:lTg",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000665 ["help", "version", "trace", "count",
666 "report", "no-report", "summary",
667 "file=", "missing",
668 "ignore-module=", "ignore-dir=",
Skip Montanarocafc8112004-04-07 15:46:05 +0000669 "coverdir=", "listfuncs",
Christian Heimes380f7f22008-02-28 11:19:05 +0000670 "trackcalls", "timing"])
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000671
Guido van Rossumb940e112007-01-10 16:19:56 +0000672 except getopt.error as msg:
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000673 sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
674 sys.stderr.write("Try `%s --help' for more information\n"
675 % sys.argv[0])
676 sys.exit(1)
677
678 trace = 0
679 count = 0
680 report = 0
681 no_report = 0
682 counts_file = None
683 missing = 0
684 ignore_modules = []
685 ignore_dirs = []
686 coverdir = None
687 summary = 0
688 listfuncs = False
Skip Montanarocafc8112004-04-07 15:46:05 +0000689 countcallers = False
Christian Heimes380f7f22008-02-28 11:19:05 +0000690 timing = False
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000691
692 for opt, val in opts:
693 if opt == "--help":
Éric Araujoe7d36fe2011-04-17 16:48:52 +0200694 _usage(sys.stdout)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000695 sys.exit(0)
696
697 if opt == "--version":
698 sys.stdout.write("trace 2.0\n")
699 sys.exit(0)
700
Skip Montanarocafc8112004-04-07 15:46:05 +0000701 if opt == "-T" or opt == "--trackcalls":
702 countcallers = True
703 continue
704
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000705 if opt == "-l" or opt == "--listfuncs":
706 listfuncs = True
707 continue
708
Christian Heimes380f7f22008-02-28 11:19:05 +0000709 if opt == "-g" or opt == "--timing":
710 timing = True
711 continue
712
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000713 if opt == "-t" or opt == "--trace":
714 trace = 1
715 continue
716
717 if opt == "-c" or opt == "--count":
718 count = 1
719 continue
720
721 if opt == "-r" or opt == "--report":
722 report = 1
723 continue
724
725 if opt == "-R" or opt == "--no-report":
726 no_report = 1
727 continue
728
729 if opt == "-f" or opt == "--file":
730 counts_file = val
731 continue
732
733 if opt == "-m" or opt == "--missing":
734 missing = 1
735 continue
736
737 if opt == "-C" or opt == "--coverdir":
738 coverdir = val
739 continue
740
741 if opt == "-s" or opt == "--summary":
742 summary = 1
743 continue
744
745 if opt == "--ignore-module":
Georg Brandlfceab5a2008-01-19 20:08:23 +0000746 for mod in val.split(","):
747 ignore_modules.append(mod.strip())
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000748 continue
749
750 if opt == "--ignore-dir":
751 for s in val.split(os.pathsep):
752 s = os.path.expandvars(s)
753 # should I also call expanduser? (after all, could use $HOME)
754
755 s = s.replace("$prefix",
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100756 os.path.join(sys.base_prefix, "lib",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000757 "python" + sys.version[:3]))
758 s = s.replace("$exec_prefix",
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100759 os.path.join(sys.base_exec_prefix, "lib",
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000760 "python" + sys.version[:3]))
761 s = os.path.normpath(s)
762 ignore_dirs.append(s)
763 continue
764
765 assert 0, "Should never get here"
766
767 if listfuncs and (count or trace):
768 _err_exit("cannot specify both --listfuncs and (--trace or --count)")
769
Skip Montanarocafc8112004-04-07 15:46:05 +0000770 if not (count or trace or report or listfuncs or countcallers):
771 _err_exit("must specify one of --trace, --count, --report, "
772 "--listfuncs, or --trackcalls")
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000773
774 if report and no_report:
775 _err_exit("cannot specify both --report and --no-report")
776
777 if report and not counts_file:
778 _err_exit("--report requires a --file")
779
780 if no_report and len(prog_argv) == 0:
781 _err_exit("missing name of file to run")
782
783 # everything is ready
784 if report:
785 results = CoverageResults(infile=counts_file, outfile=counts_file)
786 results.write_results(missing, summary=summary, coverdir=coverdir)
787 else:
788 sys.argv = prog_argv
789 progname = prog_argv[0]
790 sys.path[0] = os.path.split(progname)[0]
791
792 t = Trace(count, trace, countfuncs=listfuncs,
Skip Montanarocafc8112004-04-07 15:46:05 +0000793 countcallers=countcallers, ignoremods=ignore_modules,
794 ignoredirs=ignore_dirs, infile=counts_file,
Christian Heimes380f7f22008-02-28 11:19:05 +0000795 outfile=counts_file, timing=timing)
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000796 try:
Alexander Belopolsky3f8ecab2010-07-21 17:43:42 +0000797 with open(progname) as fp:
798 code = compile(fp.read(), progname, 'exec')
Georg Brandl8f9f4662010-08-01 08:35:29 +0000799 # try to emulate __main__ namespace as much as possible
800 globs = {
801 '__file__': progname,
802 '__name__': '__main__',
803 '__package__': None,
804 '__cached__': None,
805 }
806 t.runctx(code, globs, globs)
Guido van Rossumb940e112007-01-10 16:19:56 +0000807 except IOError as err:
Jeremy Hylton38732e12003-04-21 22:04:46 +0000808 _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000809 except SystemExit:
810 pass
811
812 results = t.results()
813
814 if not no_report:
815 results.write_results(missing, summary=summary, coverdir=coverdir)
816
Alexander Belopolsky44454af2010-11-20 18:21:07 +0000817# Deprecated API
818def usage(outfile):
819 _warn("The trace.usage() function is deprecated",
820 DeprecationWarning, 2)
821 _usage(outfile)
822
823class Ignore(_Ignore):
824 def __init__(self, modules=None, dirs=None):
825 _warn("The class trace.Ignore is deprecated",
826 DeprecationWarning, 2)
827 _Ignore.__init__(self, modules, dirs)
828
829def modname(path):
830 _warn("The trace.modname() function is deprecated",
831 DeprecationWarning, 2)
832 return _modname(path)
833
834def fullmodname(path):
835 _warn("The trace.fullmodname() function is deprecated",
836 DeprecationWarning, 2)
837 return _fullmodname(path)
838
839def find_lines_from_code(code, strs):
840 _warn("The trace.find_lines_from_code() function is deprecated",
841 DeprecationWarning, 2)
842 return _find_lines_from_code(code, strs)
843
844def find_lines(code, strs):
845 _warn("The trace.find_lines() function is deprecated",
846 DeprecationWarning, 2)
847 return _find_lines(code, strs)
848
849def find_strings(filename, encoding=None):
850 _warn("The trace.find_strings() function is deprecated",
851 DeprecationWarning, 2)
852 return _find_strings(filename, encoding=None)
853
854def find_executable_linenos(filename):
855 _warn("The trace.find_executable_linenos() function is deprecated",
856 DeprecationWarning, 2)
857 return _find_executable_linenos(filename)
858
Jeremy Hylton4edaa0d2003-02-18 15:06:17 +0000859if __name__=='__main__':
860 main()