def __init__(self, *args, **kwargs): self.sema = Semaphore(0) self._output = [] self.running = True self._plugins = [] pylintrc = kwargs.pop('pylintrc', None) super(PidaLinter, self).__init__(*args, **kwargs) #self.load_plugin_modules(self._plugins) from pylint import checkers checkers.initialize(self) #self._rcfile = gconfig = os.path.join( environment.get_plugin_global_settings_path('python_lint'), 'pylintrc') if os.path.exists(gconfig): self.read_config_file(gconfig) if pylintrc and os.path.exists(pylintrc): self.read_config_file(pylintrc) config_parser = self._config_parser if config_parser.has_option('MASTER', 'load-plugins'): plugins = get_csv(config_parser.get('MASTER', 'load-plugins')) self.load_plugin_modules(plugins) try: self.load_config_file() except Exception, e: log.exception(e) log.error(_("pylint couldn't load your config file: %s") %e)
def process_tokens(self, tokens): """process tokens from the current module to search for module/block level options """ comment = tokenize.COMMENT newline = tokenize.NEWLINE #line_num = 0 for (tok_type, _, start, _, line) in tokens: if tok_type not in (comment, newline): continue #if start[0] == line_num: # continue match = OPTION_RGX.search(line) if match is None: continue if match.group(1).strip() == "disable-all": self.add_message('I0013', line=start[0]) self._ignore_file = True return try: opt, value = match.group(1).split('=', 1) except ValueError: self.add_message('I0010', args=match.group(1).strip(), line=start[0]) continue opt = opt.strip() #line_num = start[0] if opt in self._options_methods and not opt.endswith('-report'): meth = self._options_methods[opt] for msgid in get_csv(value): try: meth(msgid, 'module', start[0]) except UnknownMessage: self.add_message('E0012', args=msgid, line=start[0]) else: self.add_message('E0011', args=opt, line=start[0])
def cb_help_message(self, option, opt_name, value, parser): """optik callback for printing some help about a particular message""" self.linter.help_message(get_csv(value)) sys.exit(0)
def cb_add_plugins(self, name, value): """callback for option preprocessing (ie before optik parsing)""" self._plugins.extend(get_csv(value))
def __init__(self, args, reporter=None): self._rcfile = None self._plugins = [] preprocess_options(args, { # option: (callback, takearg) 'rcfile': (self.cb_set_rcfile, True), 'load-plugins': (self.cb_add_plugins, True), }) self.linter = linter = self.LinterClass(( ('rcfile', {'action' : 'callback', 'callback' : lambda *args: 1, 'type': 'string', 'metavar': '<file>', 'help' : 'Specify a configuration file.'}), ('init-hook', {'action' : 'callback', 'type' : 'string', 'metavar': '<code>', 'callback' : cb_init_hook, 'help' : 'Python code to execute, usually for sys.path \ manipulation such as pygtk.require().'}), ('help-msg', {'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>', 'callback' : self.cb_help_message, 'group': 'Commands', 'help' : '''Display a help message for the given message id and \ exit. The value may be a comma separated list of message ids.'''}), ('list-msgs', {'action' : 'callback', 'metavar': '<msg-id>', 'callback' : self.cb_list_messages, 'group': 'Commands', 'help' : "Generate pylint's full documentation."}), ('generate-rcfile', {'action' : 'callback', 'callback' : self.cb_generate_config, 'group': 'Commands', 'help' : '''Generate a sample configuration file according to \ the current configuration. You can put other options before this one to get \ them in the generated configuration.'''}), ('generate-man', {'action' : 'callback', 'callback' : self.cb_generate_manpage, 'group': 'Commands', 'help' : "Generate pylint's man page.",'hide': 'True'}), ('errors-only', {'action' : 'callback', 'callback' : self.cb_error_mode, 'short': 'e', 'help' : '''In error mode, checkers without error messages are \ disabled and for others, only the ERROR messages are displayed, and no reports \ are done by default'''}), ('profile', {'type' : 'yn', 'metavar' : '<y_or_n>', 'default': False, 'help' : 'Profiled execution.'}), ), option_groups=self.option_groups, reporter=reporter, pylintrc=self._rcfile) # register standard checkers from pylint import checkers checkers.initialize(linter) # load command line plugins linter.load_plugin_modules(self._plugins) # add some help section linter.add_help_section('Environment variables', config.ENV_HELP) linter.add_help_section('Output', ''' Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occured which prevented pylint from doing further \ processing. ''') linter.add_help_section('Output status code', ''' Pylint should leave with following status code: * 0 if everything went fine * 1 if some fatal message issued * 2 if some error message issued * 4 if some warning message issued * 8 if some refactor message issued * 16 if some convention message issued * 32 on usage error status 1 to 16 will be bit-ORed so you can know which different categories has been issued by analysing pylint output status code ''') # read configuration linter.disable_message('W0704') linter.read_config_file() # is there some additional plugins in the file configuration, in config_parser = linter._config_parser if config_parser.has_option('MASTER', 'load-plugins'): plugins = get_csv(config_parser.get('MASTER', 'load-plugins')) linter.load_plugin_modules(plugins) # now we can load file config and command line, plugins (which can # provide options) have been registered linter.load_config_file() if reporter: # if a custom reporter is provided as argument, it may be overriden # by file parameters, so re-set it here, but before command line # parsing so it's still overrideable by command line option linter.set_reporter(reporter) args = linter.load_command_line_configuration(args) if not args: print linter.help() sys.exit(32) # insert current working directory to the python path to have a correct # behaviour sys.path.insert(0, os.getcwd()) if self.linter.config.profile: print >> sys.stderr, '** profiled run' from hotshot import Profile, stats prof = Profile('stones.prof') prof.runcall(linter.check, args) prof.close() data = stats.load('stones.prof') data.strip_dirs() data.sort_stats('time', 'calls') data.print_stats(30) else: linter.check(args) sys.path.pop(0) sys.exit(self.linter.msg_status)