diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-06-02 22:23:34 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-06-02 22:23:34 -0400 |
commit | 392bf6cab5c0e72b5811f57b8e157424149ce81d (patch) | |
tree | b6432c1afa09388fddef037c72fe29f507e33c28 | |
parent | ac99d3f122f0a4133c609955f69a755fc8eaaae9 (diff) | |
download | python-coveragepy-git-392bf6cab5c0e72b5811f57b8e157424149ce81d.tar.gz |
Better way to figure out if a file is installed with Python.
-rw-r--r-- | coverage/control.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/coverage/control.py b/coverage/control.py index f9d23066..b564819b 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -61,6 +61,11 @@ class coverage: # The default exclude pattern. self.exclude('# *pragma[: ]*[nN][oO] *[cC][oO][vV][eE][rR]') + # The prefix for files considered "installed with the interpreter". + if not self.cover_pylib: + os_file = self.file_locator.canonical_filename(os.__file__) + self.pylib_prefix = os.path.split(os_file)[0] + def _should_trace(self, filename, frame): """Decide whether to trace execution in `filename` @@ -89,9 +94,9 @@ class coverage: canonical = self.file_locator.canonical_filename(filename) # If we aren't supposed to trace installed code, then check if this is - # near the Python interpreter and skip it if so. + # near the Python standard library and skip it if so. if not self.cover_pylib: - if canonical.startswith(self.sysprefix): + if canonical.startswith(self.pylib_prefix): return False return canonical |