コード例 #1
0
ファイル: lint.py プロジェクト: MaraKovalcik/Flask
class Run(object):
    """helper class to use as main for pylint :

    run(*sys.argv[1:])
    """
    LinterClass = PyLinter
    option_groups = (('Commands',
                      'Options which are actually commands. Options in this \
group are mutually exclusive.'), )

    def __init__(self, args, reporter=None, exit=True):
        self._rcfile = None
        self._plugins = []
        try:
            preprocess_options(
                args,
                {
                    # option: (callback, takearg)
                    'init-hook': (cb_init_hook, True),
                    'rcfile': (self.cb_set_rcfile, True),
                    'load-plugins': (self.cb_add_plugins, True),
                })
        except ArgumentPreprocessingError, ex:
            print >> sys.stderr, ex
            sys.exit(32)

        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',
                'callback':
                lambda *args: 1,
                'type':
                'string',
                'metavar':
                '<code>',
                'level':
                1,
                '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',
                'level': 1,
                'help': "Generate pylint's messages."
            }),
            ('full-documentation', {
                'action': 'callback',
                'metavar': '<msg-id>',
                'callback': self.cb_full_documentation,
                'group': 'Commands',
                'level': 1,
                '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,
                'hide': True,
                'help': 'Profiled execution.'
            }),
        ),
                                                option_groups=self.
                                                option_groups,
                                                pylintrc=self._rcfile)
        # register standard checkers
        linter.load_default_plugins()
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section('Environment variables',
                                config.ENV_HELP,
                                level=1)
        # pylint: disable=bad-continuation
        linter.add_help_section(
            'Output',
            'Using the default text output, the message format is :                          \n'
            '                                                                                \n'
            '        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                \n'
            '                                                                                \n'
            'There are 5 kind of message types :                                             \n'
            '    * (C) convention, for programming standard violation                        \n'
            '    * (R) refactor, for bad code smell                                          \n'
            '    * (W) warning, for python specific problems                                 \n'
            '    * (E) error, for probable bugs in the code                                  \n'
            '    * (F) fatal, if an error occurred which prevented pylint from doing further\n'
            'processing.\n',
            level=1)
        linter.add_help_section(
            'Output status code',
            'Pylint should leave with following status code:                                 \n'
            '    * 0 if everything went fine                                                 \n'
            '    * 1 if a fatal message was issued                                           \n'
            '    * 2 if an error message was issued                                          \n'
            '    * 4 if a warning message was issued                                         \n'
            '    * 8 if a refactor message was issued                                        \n'
            '    * 16 if a convention message was issued                                     \n'
            '    * 32 on usage error                                                         \n'
            '                                                                                \n'
            'status 1 to 16 will be bit-ORed so you can know which different categories has\n'
            'been issued by analysing pylint output status code\n',
            level=1)
        # read configuration
        linter.disable('pointless-except')
        linter.disable('suppressed-message')
        linter.disable('useless-suppression')
        linter.read_config_file()
        config_parser = linter.cfgfile_parser
        # run init hook, if present, before loading plugins
        if config_parser.has_option('MASTER', 'init-hook'):
            cb_init_hook('init-hook',
                         unquote(config_parser.get('MASTER', 'init-hook')))
        # is there some additional plugins in the file configuration, in
        if config_parser.has_option('MASTER', 'load-plugins'):
            plugins = splitstrip(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 overridden
            # 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)
        try:
            args = linter.load_command_line_configuration(args)
        except SystemExit, exc:
            if exc.code == 2:  # bad options
                exc.code = 32
            raise
コード例 #2
0
 def test(self):
     self.assertEqual(tu.unquote('"toto"'), 'toto')
     self.assertEqual(tu.unquote("'l'inenarrable toto'"),
                      "l'inenarrable toto")
     self.assertEqual(tu.unquote("no quote"), "no quote")
コード例 #3
0
 def test(self):
     self.assertEqual(tu.unquote('"toto"'), 'toto')
     self.assertEqual(tu.unquote("'l'inenarrable toto'"), "l'inenarrable toto")
     self.assertEqual(tu.unquote("no quote"), "no quote")