pylint.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import re
  3. from prospector.formatters.base import Formatter
  4. class PylintFormatter(Formatter):
  5. """
  6. This formatter outputs messages in the same way as pylint -f parseable , which is used by several
  7. tools to parse pylint output. This formatter is therefore a compatibility shim between tools built
  8. on top of pylint and prospector itself.
  9. """
  10. def render(self, summary=True, messages=True, profile=False):
  11. # this formatter will always ignore the summary and profile
  12. cur_loc = None
  13. output = []
  14. for message in sorted(self.messages):
  15. if cur_loc != message.location.path:
  16. cur_loc = message.location.path
  17. module_name = self._make_path(message.location.path).replace(os.path.sep, ".")
  18. module_name = re.sub(r"(\.__init__)?\.py$", "", module_name)
  19. header = "************* Module %s" % module_name
  20. output.append(header)
  21. # ={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
  22. # prospector/configuration.py:65: [missing-docstring(missing-docstring), build_default_sources] \
  23. # Missing function docstring
  24. template = "%(path)s:%(line)s: [%(code)s(%(source)s), %(function)s] %(message)s"
  25. output.append(
  26. template
  27. % {
  28. "path": self._make_path(message.location.path),
  29. "line": message.location.line,
  30. "source": message.source,
  31. "code": message.code,
  32. "function": message.location.function,
  33. "message": message.message.strip(),
  34. }
  35. )
  36. return "\n".join(output)