summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/control.py11
2 files changed, 11 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6684e483..5321af07 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,10 @@ Version 3.0b3
- Added clear_exclude() and get_exclude_list() methods for programmatic
manipulation of the exclude regexes.
+- Improved the finding of code files. For example, .pyc files that have been
+ installed after compiling are now located correctly. Thanks, Detlev
+ Offenbach.
+
Version 3.0b2, 30 April 2009
----------------------------
diff --git a/coverage/control.py b/coverage/control.py
index ab9112ef..3c6b55a0 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -40,25 +40,28 @@ class coverage:
should not.
"""
+ ofilename = filename
if filename == '<string>':
# There's no point in ever tracing string executions, we can't do
# anything with the data later anyway.
return False
# Compiled Python files have two filenames: frame.f_code.co_filename is
- # the filename where the .pyc was originally compiled. The second name
+ # the filename at the time the .pyc was compiled. The second name
# is __file__, which is where the .pyc was actually loaded from. Since
# .pyc files can be moved after compilation (for example, by being
# installed), we look for __file__ in the frame and prefer it to the
# co_filename value.
dunder_file = frame.f_globals.get('__file__')
if dunder_file:
+ if not dunder_file.endswith(".py"):
+ dunder_file = dunder_file[:-1]
filename = dunder_file
- if not filename.endswith(".py"):
- filename = filename[:-1]
canonical = self.file_locator.canonical_filename(filename)
-
+
+ #print "of: %r\nfn: %r\n__: %r\nca: %r\n" % (ofilename, filename, dunder_file, canonical)
+
# If we aren't supposed to trace the stdlib, then check if this is in
# the stdlib and skip it if so.
if not self.cover_stdlib: