[Python-checkins] python/dist/src/Lib trace.py,1.4,1.5
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Mon, 21 Apr 2003 15:49:20 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv4719
Modified Files:
trace.py
Log Message:
Add helper function to get module name taking packages into account.
Index: trace.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/trace.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** trace.py 21 Apr 2003 22:04:46 -0000 1.4
--- trace.py 21 Apr 2003 22:49:17 -0000 1.5
***************
*** 158,165 ****
--- 158,184 ----
def modname(path):
"""Return a plausible module name for the patch."""
+
base = os.path.basename(path)
filename, ext = os.path.splitext(base)
return filename
+ def fullmodname(path):
+ """Return a plausible module name for the patch."""
+
+ # If the file 'path' is part of a package, then the filename isn't
+ # enough to uniquely identify it. Try to do the right thing by
+ # looking in sys.path for the longest matching prefix. We'll
+ # assume that the rest is the package name.
+
+ longest = ""
+ for dir in sys.path:
+ if path.startswith(dir) and path[len(dir)] == os.path.sep:
+ if len(dir) > len(longest):
+ longest = dir
+
+ base = path[len(longest) + 1:].replace("/", ".")
+ filename, ext = os.path.splitext(base)
+ return filename
+
class CoverageResults:
def __init__(self, counts=None, calledfuncs=None, infile=None,
***************
*** 226,230 ****
if filename == "<string>":
continue
! modulename = modname(filename)
if filename.endswith(".pyc") or filename.endswith(".pyo"):
--- 245,249 ----
if filename == "<string>":
continue
! modulename = fullmodname(filename)
if filename.endswith(".pyc") or filename.endswith(".pyo"):
***************
*** 471,474 ****
--- 490,495 ----
filename = code.co_filename
if filename:
+ # XXX modname() doesn't work right for packages, so
+ # the ignore support won't work right for packages
modulename = modname(filename)
if modulename is not None: