diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-08-01 11:43:52 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-08-01 11:43:52 -0400 |
commit | 344a11e708bdc8eeb072a51d7f31f7cad58c5b17 (patch) | |
tree | a5847fa51d26f5fbe5e17db3e45eb711c3b4884b /coverage/control.py | |
parent | e6ced9a1a817c645551960eeac981c8f33536426 (diff) | |
download | python-coveragepy-git-344a11e708bdc8eeb072a51d7f31f7cad58c5b17.tar.gz |
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.
Diffstat (limited to 'coverage/control.py')
-rw-r--r-- | coverage/control.py | 20 |
1 files changed, 10 insertions, 10 deletions
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. |