From a3cb81edd6053a273447ba3821655320ed234a41 Mon Sep 17 00:00:00 2001 From: buck Date: Wed, 15 Oct 2014 12:04:05 -0700 Subject: make --source and -m play nice together --HG-- branch : __main__-support extra : rebase_source : c9ca9fddecafddd5ef4db9cc64ca1c0972130aab --- coverage/files.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 1ed7276e..5e7c35aa 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -173,6 +173,50 @@ class TreeMatcher(object): return False +class ModuleMatcher(object): + """A matcher for files in a tree.""" + def __init__(self, module_names, main_module=None): + self.modules = list(module_names) + self.main_module = main_module + self.not_imported = list(module_names) + + def __repr__(self): + if self.main_module: + main_module = ', main_module=%r' % self.main_module + else: + main_module = '' + return "" % (self.modules, main_module) + + def info(self): + """A list of strings for displaying when dumping state.""" + return ['main_module=%r' % self.main_module] + self.modules + + def add(self, module): + """Add another directory to the list we match for.""" + self.modules.append(module) + + def match(self, module_name): + """Does `module_name` indicate a module in one of our packages? + + On success, returns the matched module name, which can be different in + the case of __main__. + """ + if not module_name: + return False + elif module_name == '__main__': + module_name = self.main_module or module_name + + for m in self.modules: + if module_name.startswith(m): + if module_name == m: + return module_name + if module_name[len(m)] == '.': + # This is a module in the package + return module_name + + return False + + class FnmatchMatcher(object): """A matcher for files by filename pattern.""" def __init__(self, pats): -- cgit v1.2.1 From d05360a060187452f49302467f87ead09d27c9ba Mon Sep 17 00:00:00 2001 From: Buck Golemon Date: Fri, 14 Nov 2014 14:00:27 -0800 Subject: ModuleFinder no longer takes a main-module argument. --HG-- branch : __main__-support extra : rebase_source : 3f4c29876960153907b65b6e8e818b8228ca4ec0 extra : histedit_source : 6567adaf9c89483b71501fd91e9d3c83ed3daec7%2C2c5c8a7af95b8b26af384b9a65815d077e4313ec --- coverage/files.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 5e7c35aa..97888b62 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -175,21 +175,16 @@ class TreeMatcher(object): class ModuleMatcher(object): """A matcher for files in a tree.""" - def __init__(self, module_names, main_module=None): + def __init__(self, module_names): self.modules = list(module_names) - self.main_module = main_module self.not_imported = list(module_names) def __repr__(self): - if self.main_module: - main_module = ', main_module=%r' % self.main_module - else: - main_module = '' - return "" % (self.modules, main_module) + return "" % (self.modules) def info(self): """A list of strings for displaying when dumping state.""" - return ['main_module=%r' % self.main_module] + self.modules + return self.modules def add(self, module): """Add another directory to the list we match for.""" @@ -197,22 +192,17 @@ class ModuleMatcher(object): def match(self, module_name): """Does `module_name` indicate a module in one of our packages? - - On success, returns the matched module name, which can be different in - the case of __main__. """ if not module_name: return False - elif module_name == '__main__': - module_name = self.main_module or module_name for m in self.modules: if module_name.startswith(m): if module_name == m: - return module_name + return True if module_name[len(m)] == '.': # This is a module in the package - return module_name + return True return False -- cgit v1.2.1 From 5082e667fbc65db03d32138fcdfa087a6fc073a6 Mon Sep 17 00:00:00 2001 From: Buck Golemon Date: Fri, 14 Nov 2014 17:52:52 -0800 Subject: ned code review, part 1 --HG-- branch : __main__-support --- coverage/files.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 97888b62..332c4225 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -174,10 +174,9 @@ class TreeMatcher(object): class ModuleMatcher(object): - """A matcher for files in a tree.""" + """A matcher for modules in a tree.""" def __init__(self, module_names): self.modules = list(module_names) - self.not_imported = list(module_names) def __repr__(self): return "" % (self.modules) -- cgit v1.2.1