summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2003-04-21 22:49:17 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2003-04-21 22:49:17 (GMT)
commitdfbfe736cee70efd27cc019be2fcc2d972cdf654 (patch)
tree1fa7dd8dead99d459344f2add16addafb4c25f67 /Lib
parent38732e1065bdb9d37d481bfb25f10eab361a7bc0 (diff)
downloadcpython-dfbfe736cee70efd27cc019be2fcc2d972cdf654.zip
cpython-dfbfe736cee70efd27cc019be2fcc2d972cdf654.tar.gz
cpython-dfbfe736cee70efd27cc019be2fcc2d972cdf654.tar.bz2
Add helper function to get module name taking packages into account.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/trace.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/trace.py b/Lib/trace.py
index 6661627..0a063c7 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -157,10 +157,29 @@ class Ignore:
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,
outfile=None):
@@ -225,7 +244,7 @@ class CoverageResults:
# skip some "files" we don't care about...
if filename == "<string>":
continue
- modulename = modname(filename)
+ modulename = fullmodname(filename)
if filename.endswith(".pyc") or filename.endswith(".pyo"):
filename = filename[:-1]
@@ -470,6 +489,8 @@ class Trace:
code = frame.f_code
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:
ignore_it = self.ignore.names(filename, modulename)