Skip to content

Commit dfd952b

Browse files
committed
process path aliases in run
1 parent ebb6b39 commit dfd952b

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

coverage/control.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -678,15 +678,12 @@ def combine(self, data_paths=None, strict=False):
678678
self._post_init()
679679
self.get_data()
680680

681-
aliases = None
682-
if self.config.paths:
683-
aliases = PathAliases()
684-
for paths in self.config.paths.values():
685-
result = paths[0]
686-
for pattern in paths[1:]:
687-
aliases.add(pattern, result)
688-
689-
combine_parallel_data(self._data, aliases=aliases, data_paths=data_paths, strict=strict)
681+
combine_parallel_data(
682+
self._data,
683+
aliases=PathAliases.configure(config),
684+
data_paths=data_paths,
685+
strict=strict,
686+
)
690687

691688
def get_data(self):
692689
"""Get the collected data.

coverage/files.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ class TreeMatcher(object):
215215
somewhere in a subtree rooted at one of the directories.
216216
217217
"""
218-
def __init__(self, paths):
218+
def __init__(self, paths, aliases=None):
219+
self.aliases = aliases
219220
self.paths = list(paths)
220221

221222
def __repr__(self):
@@ -227,6 +228,9 @@ def info(self):
227228

228229
def match(self, fpath):
229230
"""Does `fpath` indicate a file in one of our trees?"""
231+
if self.aliases is not None:
232+
fpath = self.aliases.map(fpath)
233+
230234
for p in self.paths:
231235
if fpath.startswith(p):
232236
if fpath == p:
@@ -268,7 +272,8 @@ def match(self, module_name):
268272

269273
class FnmatchMatcher(object):
270274
"""A matcher for files by file name pattern."""
271-
def __init__(self, pats):
275+
def __init__(self, pats, aliases=None):
276+
self.aliases = aliases
272277
self.pats = list(pats)
273278
self.re = fnmatches_to_regex(self.pats, case_insensitive=env.WINDOWS)
274279

@@ -281,6 +286,8 @@ def info(self):
281286

282287
def match(self, fpath):
283288
"""Does `fpath` match one of our file name patterns?"""
289+
if self.aliases is not None:
290+
fpath = self.aliases.map(fpath)
284291
return self.re.match(fpath) is not None
285292

286293

@@ -408,6 +415,21 @@ def map(self, path):
408415
return path
409416

410417

418+
@classmethod
419+
def configure(cls, config):
420+
paths = config.paths
421+
if not paths:
422+
return None
423+
424+
aliases = PathAliases()
425+
for paths in paths.values():
426+
result = paths[0]
427+
for pattern in paths[1:]:
428+
aliases.add(pattern, result)
429+
return aliases
430+
431+
432+
411433
def find_python_files(dirname):
412434
"""Yield all of the importable Python files in `dirname`, recursively.
413435

coverage/inorout.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from coverage.backward import code_object
1818
from coverage.disposition import FileDisposition, disposition_init
1919
from coverage.files import TreeMatcher, FnmatchMatcher, ModuleMatcher
20-
from coverage.files import prep_patterns, find_python_files, canonical_filename
20+
from coverage.files import prep_patterns, find_python_files, canonical_filename, PathAliases
2121
from coverage.misc import CoverageException
2222
from coverage.python import source_for_file, source_for_morf
2323

@@ -132,6 +132,7 @@ def __init__(self, warn, debug):
132132

133133
def configure(self, config):
134134
"""Apply the configuration to get ready for decision-time."""
135+
aliases = PathAliases.configure(config)
135136
for src in config.source or []:
136137
if os.path.isdir(src):
137138
self.source.append(canonical_filename(src))
@@ -186,24 +187,24 @@ def debug(msg):
186187
if self.source or self.source_pkgs:
187188
against = []
188189
if self.source:
189-
self.source_match = TreeMatcher(self.source)
190+
self.source_match = TreeMatcher(self.source, aliases=aliases)
190191
against.append("trees {!r}".format(self.source_match))
191192
if self.source_pkgs:
192193
self.source_pkgs_match = ModuleMatcher(self.source_pkgs)
193194
against.append("modules {!r}".format(self.source_pkgs_match))
194195
debug("Source matching against " + " and ".join(against))
195196
else:
196197
if self.cover_paths:
197-
self.cover_match = TreeMatcher(self.cover_paths)
198+
self.cover_match = TreeMatcher(self.cover_paths, aliases=aliases)
198199
debug("Coverage code matching: {!r}".format(self.cover_match))
199200
if self.pylib_paths:
200-
self.pylib_match = TreeMatcher(self.pylib_paths)
201+
self.pylib_match = TreeMatcher(self.pylib_paths, aliases=aliases)
201202
debug("Python stdlib matching: {!r}".format(self.pylib_match))
202203
if self.include:
203-
self.include_match = FnmatchMatcher(self.include)
204+
self.include_match = FnmatchMatcher(self.include, aliases=aliases)
204205
debug("Include matching: {!r}".format(self.include_match))
205206
if self.omit:
206-
self.omit_match = FnmatchMatcher(self.omit)
207+
self.omit_match = FnmatchMatcher(self.omit, alieases=alieases)
207208
debug("Omit matching: {!r}".format(self.omit_match))
208209

209210
def should_trace(self, filename, frame=None):

0 commit comments

Comments
 (0)