Skip to content

Commit 13159a9

Browse files
committed
More details on --source filtering
1 parent 44bb585 commit 13159a9

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

coverage/control.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def __init__(
212212
self._data = self._collector = None
213213
self._plugins = None
214214
self._inorout = None
215-
self._inorout_class = InOrOut
216215
self._data_suffix = self._run_suffix = None
217216
self._exclude_re = None
218217
self._debug = None
@@ -483,7 +482,10 @@ def _init_for_start(self):
483482
plugin._coverage_enabled = False
484483

485484
# Create the file classifying substructure.
486-
self._inorout = self._inorout_class(warn=self._warn)
485+
self._inorout = InOrOut(
486+
warn=self._warn,
487+
debug=(self._debug if self._debug.should('trace') else None),
488+
)
487489
self._inorout.configure(self.config)
488490
self._inorout.plugins = self._plugins
489491
self._inorout.disp_class = self._collector.file_disposition_class

coverage/inorout.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ def module_has_file(mod):
111111
class InOrOut(object):
112112
"""Machinery for determining what files to measure."""
113113

114-
def __init__(self, warn):
114+
def __init__(self, warn, debug):
115115
self.warn = warn
116+
self.debug = debug
116117

117118
# The matchers for should_trace.
118119
self.source_match = None
@@ -177,19 +178,33 @@ def configure(self, config):
177178
for mod in [contracts, six]:
178179
self.cover_paths.append(canonical_path(mod))
179180

181+
def debug(msg):
182+
if self.debug:
183+
self.debug.write(msg)
184+
180185
# Create the matchers we need for should_trace
181186
if self.source or self.source_pkgs:
182-
self.source_match = TreeMatcher(self.source)
183-
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
187+
against = []
188+
if self.source:
189+
self.source_match = TreeMatcher(self.source)
190+
against.append("trees {!r}".format(self.source_match))
191+
if self.source_pkgs:
192+
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
193+
against.append("modules {!r}".format(self.source_pkgs_match))
194+
debug("Source matching against " + " and ".join(against))
184195
else:
185196
if self.cover_paths:
186197
self.cover_match = TreeMatcher(self.cover_paths)
198+
debug("Coverage code matching: {!r}".format(self.cover_match))
187199
if self.pylib_paths:
188200
self.pylib_match = TreeMatcher(self.pylib_paths)
201+
debug("Python stdlib matching: {!r}".format(self.pylib_match))
189202
if self.include:
190203
self.include_match = FnmatchMatcher(self.include)
204+
debug("Include matching: {!r}".format(self.include_match))
191205
if self.omit:
192206
self.omit_match = FnmatchMatcher(self.omit)
207+
debug("Omit matching: {!r}".format(self.omit_match))
193208

194209
def should_trace(self, filename, frame=None):
195210
"""Decide whether to trace execution in `filename`, with a reason.
@@ -309,12 +324,21 @@ def check_include_omit_etc(self, filename, frame):
309324
# about the outer bound of what to measure and we don't have to apply
310325
# any canned exclusions. If they didn't, then we have to exclude the
311326
# stdlib and coverage.py directories.
312-
if self.source_match:
313-
if self.source_pkgs_match.match(modulename):
314-
if modulename in self.source_pkgs_unmatched:
315-
self.source_pkgs_unmatched.remove(modulename)
316-
elif not self.source_match.match(filename):
317-
return "falls outside the --source trees"
327+
if self.source_match or self.source_pkgs_match:
328+
extra = ""
329+
ok = False
330+
if self.source_pkgs_match:
331+
if self.source_pkgs_match.match(modulename):
332+
ok = True
333+
if modulename in self.source_pkgs_unmatched:
334+
self.source_pkgs_unmatched.remove(modulename)
335+
else:
336+
extra = "module {!r} ".format(modulename)
337+
if not ok and self.source_match:
338+
if self.source_match.match(filename):
339+
ok = True
340+
if not ok:
341+
return extra + "falls outside the --source spec"
318342
elif self.include_match:
319343
if not self.include_match.match(filename):
320344
return "falls outside the --include trees"

0 commit comments

Comments
 (0)