def run(self, found_files):
        messages = []

        for code_file in found_files.iter_module_paths():
            try:
                contents = read_py_file(code_file)
                tree = ast.parse(
                    contents,
                    filename=code_file,
                )
            except CouldNotHandleEncoding as err:
                messages.append(
                    make_tool_error_message(
                        code_file,
                        'mccabe',
                        'MC0000',
                        message='Could not handle the encoding of this file: %s'
                        % err.encoding))
                continue
            except SyntaxError as err:
                messages.append(
                    make_tool_error_message(code_file,
                                            'mccabe',
                                            'MC0000',
                                            line=err.lineno,
                                            character=err.offset,
                                            message='Syntax Error'))
                continue
            except TypeError:
                messages.append(
                    make_tool_error_message(code_file,
                                            'mccabe',
                                            'MC0000',
                                            message='Unable to parse file'))
                continue

            visitor = PathGraphingAstVisitor()
            visitor.preorder(tree, visitor)

            for graph in visitor.graphs.values():
                complexity = graph.complexity()
                if complexity > self.max_complexity:
                    location = Location(path=code_file,
                                        module=None,
                                        function=graph.entity,
                                        line=graph.lineno,
                                        character=0,
                                        absolute_path=True)
                    message = Message(
                        source='mccabe',
                        code='MC0001',
                        location=location,
                        message='%s is too complex (%s)' % (
                            graph.entity,
                            complexity,
                        ),
                    )
                    messages.append(message)

        return self.filter_messages(messages)
Example #2
0
    def run(self, found_files):
        messages = []

        checker = ConventionChecker()

        for code_file in found_files.iter_module_paths():
            try:
                for error in checker.check_source(read_py_file(code_file),
                                                  code_file, None):

                    location = Location(
                        path=code_file,
                        module=None,
                        function="",
                        line=error.line,
                        character=0,
                        absolute_path=True,
                    )
                    message = Message(
                        source="pydocstyle",
                        code=error.code,
                        location=location,
                        message=error.message.partition(":")[2].strip(),
                    )
                    messages.append(message)
            except CouldNotHandleEncoding as err:
                messages.append(
                    make_tool_error_message(
                        code_file,
                        "pydocstyle",
                        "D000",
                        message=
                        f"Could not handle the encoding of this file: {err.encoding}",
                    ))
                continue
            except AllError as exc:
                # pydocstyle's Parser.parse_all method raises AllError when an
                # attempt to analyze the __all__ definition has failed.  This
                # occurs when __all__ is too complex to be parsed.
                messages.append(
                    make_tool_error_message(
                        code_file,
                        "pydocstyle",
                        "D000",
                        line=1,
                        character=0,
                        message=exc.args[0],
                    ))
                continue

        return self.filter_messages(messages)
Example #3
0
    def run(self, found_files):
        messages = []

        checker = PEP257Checker()

        for code_file in found_files.iter_module_paths():
            try:
                for error in checker.check_source(
                    read_py_file(code_file),
                    code_file,
                    None
                ):

                    location = Location(
                        path=code_file,
                        module=None,
                        function='',
                        line=error.line,
                        character=0,
                        absolute_path=True,
                    )
                    message = Message(
                        source='pep257',
                        code=error.code,
                        location=location,
                        message=error.message.partition(':')[2].strip(),
                    )
                    messages.append(message)
            except CouldNotHandleEncoding as err:
                messages.append(make_tool_error_message(
                    code_file, 'pep257', 'D000',
                    message='Could not handle the encoding of this file: %s' % err.encoding
                ))
                continue
            except AllError as exc:
                # pep257's Parser.parse_all method raises AllError when an
                # attempt to analyze the __all__ definition has failed.  This
                # occurs when __all__ is too complex to be parsed.
                messages.append(make_tool_error_message(
                    code_file, 'pep257', 'D000',
                    line=1, character=0,
                    message=exc.args[0]
                ))
                continue

        return self.filter_messages(messages)
Example #4
0
 def scavenge(self, _=None):
     # The argument is a list of paths, but we don't care
     # about that as we use the found_files object. The
     # argument is here to explicitly acknowledge that we
     # are overriding the Vulture.scavenge method.
     for module in self._files.iter_module_paths():
         try:
             module_string = read_py_file(module)
         except CouldNotHandleEncoding as err:
             self._internal_messages.append(make_tool_error_message(
                 module, 'vulture', 'V000',
                 message='Could not handle the encoding of this file: %s' % err.encoding
             ))
             continue
         self.file = module
         self.scan(module_string)
Example #5
0
 def scavenge(self, _=None):
     # The argument is a list of paths, but we don't care
     # about that as we use the found_files object. The
     # argument is here to explicitly acknowledge that we
     # are overriding the Vulture.scavenge method.
     for module in self._files.iter_module_paths():
         try:
             module_string = read_py_file(module)
         except CouldNotHandleEncoding as err:
             self._internal_messages.append(
                 make_tool_error_message(
                     module,
                     'vulture',
                     'V000',
                     message='Could not handle the encoding of this file: %s'
                     % err.encoding))
             continue
         self.file = module
         self.scan(module_string)