From 344a11e708bdc8eeb072a51d7f31f7cad58c5b17 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 1 Aug 2010 11:43:52 -0400 Subject: Virtualenv3 moves random.py into the virtualenv, so we can't use it as the control any more. Just examine all the modules we import, and use all their locations as the pylib directories. --- coverage/control.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'coverage/control.py') diff --git a/coverage/control.py b/coverage/control.py index 6ec36e77..7ab046cb 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -141,16 +141,16 @@ class coverage(object): # The dirs for files considered "installed with the interpreter". self.pylib_dirs = [] if not self.config.cover_pylib: - # Look at where the "os" module is located. That's the indication - # for "installed with the interpreter". - os_dir = self._canonical_dir(os.__file__) - self.pylib_dirs.append(os_dir) - - # In a virtualenv, there're actually two lib directories. Find the - # other one. This is kind of ad-hoc, but it works. - random_dir = self._canonical_dir(random.__file__) - if random_dir != os_dir: - self.pylib_dirs.append(random_dir) + # Look at where some standard modules are located. That's the + # indication for "installed with the interpreter". In some + # environments (virtualenv, for example), these modules may be + # spread across a few locations. Look at all the candidate modules + # we've imported, and take all the different ones. + for m in (atexit, os, random, socket): + if hasattr(m, "__file__"): + m_dir = self._canonical_dir(m.__file__) + if m_dir not in self.pylib_dirs: + self.pylib_dirs.append(m_dir) # To avoid tracing the coverage code itself, we skip anything located # where we are. -- cgit v1.2.1