How to use the prospector.formatters.base.Formatter function in prospector

To help you get started, we’ve selected a few prospector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyCQA / prospector / prospector / formatters / pylint.py View on Github external
import os
import re
from prospector.formatters.base import Formatter


class PylintFormatter(Formatter):
    """
    This formatter outputs messages in the same way as pylint -f parseable , which is used by several
    tools to parse pylint output. This formatter is therefore a compatability shim between tools built
    on top of pylint and prospector itself.
    """

    def render(self, summary=True, messages=True):
        # this formatter will always ignore the summary
        cur_loc = None
        output = []
        for message in sorted(self.messages):
            if cur_loc != message.location.path:
                cur_loc = message.location.path
                module_name = message.location.path.replace(os.path.sep, '.')
                module_name = re.sub(r'(\.__init__)?\.py$', '', module_name)
github PyCQA / prospector / prospector / formatters / json.py View on Github external
from __future__ import absolute_import

import json

from datetime import datetime

from prospector.formatters.base import Formatter


__all__ = (
    'JsonFormatter',
)


# pylint: disable=R0903
class JsonFormatter(Formatter):
    def render(self, summary=True, messages=True):
        output = {}

        if summary:
            # we need to slightly change the types and format
            # of a few of the items in the summary to make
            # them play nice with JSON formatting
            munged = {}
            for key, value in self.summary.items():
                if isinstance(value, datetime):
                    munged[key] = str(value)
                else:
                    munged[key] = value
            output['summary'] = munged

        if messages:
github PyCQA / prospector / prospector / formatters / yaml.py View on Github external
from __future__ import absolute_import

import yaml

from prospector.formatters.base import Formatter


__all__ = (
    'YamlFormatter',
)


# pylint: disable=too-few-public-methods
class YamlFormatter(Formatter):
    def render(self, summary=True, messages=True, profile=False):
        output = {}

        if summary:
            output['summary'] = self.summary

        if profile:
            output['profile'] = self.profile.as_dict()

        if messages:
            output['messages'] = [m.as_dict() for m in self.messages]

        return yaml.safe_dump(
            output,
            indent=2,
            default_flow_style=False,
github PyCQA / prospector / prospector / formatters / xunit.py View on Github external
from prospector.formatters.base import Formatter
from xml.dom.minidom import Document


class XunitFormatter(Formatter):

    """
    This formatter outputs messages in the Xunit xml format, which is used by several
    CI tools to parse output. This formatter is therefore a compatability shim between tools built
    to use Xunit and prospector itself.
    """

    def render(self, summary=True, messages=True, profile=False):
        xml_doc = Document()

        testsuite_el = xml_doc.createElement('testsuite')
        testsuite_el.setAttribute('errors', str(self.summary['message_count']))
        testsuite_el.setAttribute('failures', '0')
        testsuite_el.setAttribute('name', 'prospector-%s' % '-'.join(self.summary['tools']))
        testsuite_el.setAttribute('tests', str(self.summary['message_count']))
        testsuite_el.setAttribute('time', str(self.summary['time_taken']))
github PyCQA / prospector / prospector / formatters / text.py View on Github external
from prospector.formatters.base import Formatter


__all__ = (
    'TextFormatter',
)


# pylint: disable=unnecessary-lambda


class TextFormatter(Formatter):
    summary_labels = (
        ('started', 'Started'),
        ('completed', 'Finished'),
        ('time_taken', 'Time Taken', lambda x: '%s seconds' % x),
        ('formatter', 'Formatter'),
        ('profiles', 'Profiles'),
        ('strictness', 'Strictness'),
        ('libraries', 'Libraries Used', lambda x: ', '.join(x)),
        ('tools', 'Tools Run', lambda x: ', '.join(x)),
        ('adaptors', 'Adaptors', lambda x: ', '.join(x)),
        ('message_count', 'Messages Found'),
        ('external_config', 'External Config'),
    )

    def render_summary(self):
        output = [