diff options
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/lint.py | 28 | ||||
-rw-r--r-- | pylint/utils.py | 37 |
2 files changed, 44 insertions, 21 deletions
diff --git a/pylint/lint.py b/pylint/lint.py index 5cfec9bf7..bbdeada14 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -962,11 +962,9 @@ class PyLinter( results_queue = manager.Queue() # Send files to child linters. - expanded_files = [] - for descr in self.expand_files(files_or_modules): - modname, filepath, is_arg = descr["name"], descr["path"], descr["isarg"] - if self.should_analyze_file(modname, filepath, is_argument=is_arg): - expanded_files.append(descr) + expanded_files = utils.expand_files( + files_or_modules, self, self.config.black_list, self.config.black_list_re + ) # do not start more jobs than needed for _ in range(min(self.config.jobs, len(expanded_files))): @@ -1046,7 +1044,10 @@ class PyLinter( if interfaces.implements(checker, interfaces.IAstroidChecker): walker.add_checker(checker) # build ast and check modules or packages - for module_desc in self.expand_files(files_or_modules): + expanded_files = utils.expand_files( + files_or_modules, self, self.config.black_list, self.config.black_list_re + ) + for module_desc in expanded_files: modname = module_desc.name filepath = module_desc.path if not module_desc.isarg and not self.should_analyze_file( @@ -1079,21 +1080,6 @@ class PyLinter( for checker in reversed(_checkers): checker.close() - def expand_files(self, modules): - """get modules and errors from a list of modules and handle errors - """ - result, errors = utils.expand_modules( - modules, self.config.black_list, self.config.black_list_re - ) - for error in errors: - message = modname = error["mod"] - key = error["key"] - self.set_current_module(modname) - if key == "fatal": - message = str(error["ex"]).replace(os.getcwd() + os.sep, "") - self.add_message(key, args=message) - return result - def set_current_module(self, modname, filepath=None): """set the name of the currently analyzed module and init statistics for it diff --git a/pylint/utils.py b/pylint/utils.py index a70c4bb53..9d6283577 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -1152,6 +1152,43 @@ ModuleDescription = collections.namedtuple( ) +# TODO: Replace linter with a message store as part of #938 +def expand_files(files_or_modules, linter, black_list, black_list_re): + """ + Run :func:`expand_modules` and turn errors into messages. + + :param files_or_modules: A list of files, directories, modules, or packages + to turn into :class:`ModuleDescription`s. + :type files_or_modules: :obj:`list` of :obj:`str` + + :param linter: A linter to store messages onto. + :type linter: :class:`pylint.PyLinter` + + :param black_list: A list of files or directories to ignore. + :type black_list: :obj:`list` or :obj:`tuple` + + :param black_list_re: A list of regex patterns. Any files, directories, + modules, or packages matching against any of these patterns will be + ignored. + :type black_list_re: :obj:`list`: of :obj:`re.RegexObject` + + :returns: The :class:`ModuleDescription`s for each found file, directory, + module, or package. + :rtype: :obj:`list` of :class:`ModuleDescription` + """ + result, errors = expand_modules(files_or_modules, black_list, black_list_re) + + for error in errors: + message = modname = error["mod"] + key = error["key"] + linter.set_current_module(modname) + if key == "fatal": + message = str(error["ex"]).replace(os.getcwd() + os.sep, "") + linter.add_message(key, args=message) + + return result + + def expand_modules(files_or_modules, black_list, black_list_re): """take a list of files/modules/packages and return the list of tuple (file, module name) which have to be actually checked |