Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # Copyright (c) 2006-2014 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2013-2014 Google, Inc.
  3. # Copyright (c) 2013 buck@yelp.com <buck@yelp.com>
  4. # Copyright (c) 2014-2017 Claudiu Popa <pcmanticore@gmail.com>
  5. # Copyright (c) 2014 Brett Cannon <brett@python.org>
  6. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  7. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  8. # Copyright (c) 2016 Moises Lopez <moylop260@vauxoo.com>
  9. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  10. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  11. """utilities methods and classes for checkers
  12. Base id of standard checkers (used in msg and report ids):
  13. 01: base
  14. 02: classes
  15. 03: format
  16. 04: import
  17. 05: misc
  18. 06: variables
  19. 07: exceptions
  20. 08: similar
  21. 09: design_analysis
  22. 10: newstyle
  23. 11: typecheck
  24. 12: logging
  25. 13: string_format
  26. 14: string_constant
  27. 15: stdlib
  28. 16: python3
  29. 17: refactoring
  30. 18-50: not yet used: reserved for future internal checkers.
  31. 51-99: perhaps used: reserved for external checkers
  32. The raw_metrics checker has no number associated since it doesn't emit any
  33. messages nor reports. XXX not true, emit a 07 report !
  34. """
  35. import sys
  36. import tokenize
  37. import warnings
  38. from pylint.config import OptionsProviderMixIn
  39. from pylint.reporters import diff_string
  40. from pylint.utils import register_plugins
  41. from pylint.interfaces import UNDEFINED
  42. def table_lines_from_stats(stats, old_stats, columns):
  43. """get values listed in <columns> from <stats> and <old_stats>,
  44. and return a formated list of values, designed to be given to a
  45. ureport.Table object
  46. """
  47. lines = []
  48. for m_type in columns:
  49. new = stats[m_type]
  50. format = str # pylint: disable=redefined-builtin
  51. if isinstance(new, float):
  52. format = lambda num: '%.3f' % num
  53. old = old_stats.get(m_type)
  54. if old is not None:
  55. diff_str = diff_string(old, new)
  56. old = format(old)
  57. else:
  58. old, diff_str = 'NC', 'NC'
  59. lines += (m_type.replace('_', ' '), format(new), old, diff_str)
  60. return lines
  61. class BaseChecker(OptionsProviderMixIn):
  62. """base class for checkers"""
  63. # checker name (you may reuse an existing one)
  64. name = None
  65. # options level (0 will be displaying in --help, 1 in --long-help)
  66. level = 1
  67. # ordered list of options to control the ckecker behaviour
  68. options = ()
  69. # messages issued by this checker
  70. msgs = {}
  71. # reports issued by this checker
  72. reports = ()
  73. # mark this checker as enabled or not.
  74. enabled = True
  75. def __init__(self, linter=None):
  76. """checker instances should have the linter as argument
  77. linter is an object implementing ILinter
  78. """
  79. self.name = self.name.lower()
  80. OptionsProviderMixIn.__init__(self)
  81. self.linter = linter
  82. def add_message(self, msg_id, line=None, node=None, args=None, confidence=UNDEFINED):
  83. """add a message of a given type"""
  84. self.linter.add_message(msg_id, line, node, args, confidence)
  85. # dummy methods implementing the IChecker interface
  86. def open(self):
  87. """called before visiting project (i.e set of modules)"""
  88. def close(self):
  89. """called after visiting project (i.e set of modules)"""
  90. class BaseTokenChecker(BaseChecker):
  91. """Base class for checkers that want to have access to the token stream."""
  92. def process_tokens(self, tokens):
  93. """Should be overridden by subclasses."""
  94. raise NotImplementedError()
  95. def initialize(linter):
  96. """initialize linter with checkers in this package """
  97. register_plugins(linter, __path__[0])
  98. __all__ = ('BaseChecker', 'initialize')