当前位置: 首页>>代码示例>>Python>>正文


Python autopep8.parse_args函数代码示例

本文整理汇总了Python中autopep8.parse_args函数的典型用法代码示例。如果您正苦于以下问题:Python parse_args函数的具体用法?Python parse_args怎么用?Python parse_args使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_args函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_inplace_with_multi_files

 def test_inplace_with_multi_files(self):
     with disable_stderr():
         try:
             autopep8.parse_args(['test.py', 'dummy.py'])
             self.assertEqual("not work", "test has failed!!")
         except SystemExit as e:
             self.assertEqual(e.code, 2)
开发者ID:samv,项目名称:autopep8,代码行数:7,代码来源:test_autopep8.py

示例2: test_no_argument

 def test_no_argument(self):
     with disable_stderr():
         try:
             autopep8.parse_args([])
             self.assertEqual("not work", "test has failed!!")
         except SystemExit as e:
             self.assertEqual(e.code, 2)
开发者ID:samv,项目名称:autopep8,代码行数:7,代码来源:test_autopep8.py

示例3: check_file

    def check_file(self, path):
        """
        Check one regular file with pylint for py syntax errors.

        :param path: Path to a regular file.
        :return: False, if pylint found syntax problems, True, if pylint didn't
                 find problems, or path is not a python module or script.
        """
        inspector = PathInspector(path)
        if not inspector.is_python():
            return True
        opt_obj = pep8.StyleGuide().options
        ignore_list = self.ignored_errors.split(',') + list(opt_obj.ignore)
        opt_obj.ignore = tuple(set(ignore_list))
        runner = pep8.Checker(filename=path, options=opt_obj)
        status = runner.check_all()
        if status != 0:
            log.error('PEP8 check fail: %s', path)
            self.failed_paths.append(path)
            log.error('Trying to fix errors with autopep8')
            try:
                opt_obj = autopep8.parse_args([path,
                                               '--ignore',
                                               self.ignored_errors,
                                               '--in-place'])
                autopep8.fix_file(path, opt_obj)
            except Exception, details:
                log.error('Not able to fix errors: %s', details)
开发者ID:ldoktor,项目名称:inspektor,代码行数:28,代码来源:style.py

示例4: create_plugin_code

def create_plugin_code(code, name, category=None, menu=False, toolbar=False,
                       icon=None):
    """Create a plugin with an action that will execute 'code' when triggered.
    If 'menu' and/or 'toolbar' is True, the corresponding items will be added
    for the action.
    """

    if category is None:
        category = name

    safe_name = string.capwords(name).replace(" ", "")
    plugin_code = header.format(safe_name, name)
    if icon is None:
        plugin_code += action_noicon.format()
    else:
        plugin_code += action_icon.format(icon)
    if menu:
        plugin_code += menu_def.format(category)
    if toolbar:
        plugin_code += toolbar_def.format(category)

    # Indent code by two levels
    code = indent(code, 2 * 4)
    plugin_code += default.format(code)
    try:
        import autopep8
        plugin_code = autopep8.fix_code(plugin_code,
                                        options=autopep8.parse_args(
                                         ['--aggressive', '--aggressive', '']))
    except ImportError:
        pass
    return plugin_code
开发者ID:hyperspy,项目名称:hyperspyUI,代码行数:32,代码来源:plugincreator.py

示例5: main

def main():
    readme_path = 'README.rst'
    before_key = 'Before running autopep8.\n\n.. code-block:: python'
    after_key = 'After running autopep8.\n\n.. code-block:: python'

    (top, before, bottom) = split_readme(readme_path,
                                         before_key=before_key,
                                         after_key=after_key,
                                         end_key='Options::')

    input_code = textwrap.dedent(before)

    output_code = autopep8.fix_string(
        input_code,
        options=autopep8.parse_args(['', '--aggressive'])[0])
    compile(output_code, '<string>', 'exec', dont_inherit=True)

    new_readme = '\n\n'.join([
        top,
        before_key, before,
        after_key, indent(output_code),
        bottom])

    with open(readme_path, 'w') as output_file:
        output_file.write(new_readme)
开发者ID:clebergnu,项目名称:autopep8,代码行数:25,代码来源:update_readme.py

示例6: main

def main():
    readme_path = 'README.rst'
    before_key = 'Before running autopep8.\n\n.. code-block:: python'
    after_key = 'After running autopep8.\n\n.. code-block:: python'
    options_key = 'Options::'

    (top, before, bottom) = split_readme(readme_path,
                                         before_key=before_key,
                                         after_key=after_key,
                                         options_key=options_key,
                                         end_key='Features\n========')

    input_code = textwrap.dedent(before)

    output_code = autopep8.fix_code(
        input_code,
        options=autopep8.parse_args(['', '-aa']))

    check(output_code)

    new_readme = '\n\n'.join([
        top,
        before_key, before,
        after_key, indent(output_code).rstrip(),
        options_key, indent(help_message()),
        bottom])

    with open(readme_path, 'w') as output_file:
        output_file.write(new_readme)
开发者ID:genba,项目名称:autopep8,代码行数:29,代码来源:update_readme.py

示例7: gen

def gen(path,
        method=None,
        query_params=None,
        data=None,
        content_type=None):
    # generates python code representing a call via django client.
    # useful for use in testing
    method = method.lower()
    t = jinja2.Template(template)
    if method == 'get':
        r = t.render(path=path,
                     data=query_params,
                     lower_case_method=method,
                     content_type=content_type)
    else:
        if query_params:
            query_params = _encode_query_params(query_params)
            path += query_params
        if is_str_typ(data):
            data = "'%s'" % data
        r = t.render(path=path,
                     data=data,
                     lower_case_method=method,
                     query_params=query_params,
                     content_type=content_type)
    return autopep8.fix_code(
        r, options=autopep8.parse_args(['--aggressive', ''])
    )
开发者ID:SzySteve,项目名称:silk,代码行数:28,代码来源:django_test_client.py

示例8: _inner_setup

 def _inner_setup(self, line, options=()):
     with open(self.tempfile[1], 'w') as temp_file:
         temp_file.write(line)
     opts, _ = autopep8.parse_args([self.tempfile[1]] + list(options))
     sio = StringIO()
     autopep8.fix_file(filename=self.tempfile[1],
                       opts=opts,
                       output=sio)
     self.result = sio.getvalue()
开发者ID:samv,项目名称:autopep8,代码行数:9,代码来源:test_autopep8.py

示例9: _inner_setup

 def _inner_setup(self, line):
     f = open(self.tempfile[1], 'w')
     f.write(line)
     f.close()
     opts, _ = autopep8.parse_args([self.tempfile[1]])
     sio = StringIO()
     autopep8.fix_file(filename=self.tempfile[1],
                       opts=opts,
                       output=sio)
     self.result = sio.getvalue()
开发者ID:msabramo,项目名称:autopep8,代码行数:10,代码来源:test_autopep8.py

示例10: get_options

    def get_options(self):
        options = autopep8.parse_args([''])[0]
        options.max_line_length = self.settings.get(
            'max-line-length', 79)
        options.aggressive = self.settings.get('aggressive', False)
        if self.settings.get('ignore', []):
            options.ignore = ','.join(self.settings.get('ignore', []))
        if self.settings.get('select', []):
            options.select = ','.join(self.settings.get('select', []))

        return options
开发者ID:sadig,项目名称:sublime-text-2-packages,代码行数:11,代码来源:pep8_autoformat.py

示例11: test_autopep8_args

    def test_autopep8_args(self):
        # TODO see that these are passes on (use a static method in Radius?)

        args = ["hello.py"]
        us = parse_args(args)
        them = autopep8.parse_args(args)
        self.assertEqual(us.select, them.select)
        self.assertEqual(us.ignore, them.ignore)

        args = ["hello.py", "--select=E1,W1", "--ignore=W601", "--max-line-length", "120"]
        us = parse_args(args)
        them = autopep8.parse_args(args)
        self.assertEqual(us.select, them.select)
        self.assertEqual(us.ignore, them.ignore)
        self.assertEqual(us.max_line_length, them.max_line_length)

        args = ["hello.py", "--aggressive", "-v"]
        us = parse_args(args)
        them = autopep8.parse_args(args)
        self.assertEqual(us.aggressive, them.aggressive)
开发者ID:kmonsoor,项目名称:pep8radius,代码行数:20,代码来源:test_pep8radius.py

示例12: formatters

def formatters(aggressive):
    """Return list of code formatters."""
    if aggressive:
        yield autoflake.fix_code
        autopep8_options = autopep8.parse_args(
            [''] + int(aggressive) * ['--aggressive'])
    else:
        autopep8_options = None

    yield lambda code: autopep8.fix_code(code, options=autopep8_options)
    yield docformatter.format_code
    yield unify.format_code
开发者ID:generalov,项目名称:pyformat,代码行数:12,代码来源:pyformat.py

示例13: check_file

    def check_file(self, path):
        """
        Check one regular file with pylint for py syntax errors.

        :param path: Path to a regular file.
        :return: False, if pylint found syntax problems, True, if pylint didn't
                 find problems, or path is not a python module or script.
        """
        inspector = PathInspector(path=path, args=self.args)
        if inspector.is_toignore():
            return True
        if not inspector.is_python():
            return True
        try:
            opt_obj = pep8.StyleGuide().options
            ignore_list = self.args.disable.split(',') + list(opt_obj.ignore)
            opt_obj.ignore = tuple(set(ignore_list))
            # pylint: disable=E1123
            runner = pep8.Checker(filename=path, options=opt_obj)
        except Exception:
            opts = ['--ignore'] + self.args.disable.split(',')
            pep8.process_options(opts)
            runner = pep8.Checker(filename=path)
        try:
            status = runner.check_all()
        except:
            log.error('Unexpected exception while checking %s', path)
            exc_info = sys.exc_info()
            stacktrace.log_exc_info(exc_info, 'inspektor.style')
            status = 1

        if status != 0:
            log.error('PEP8 check fail: %s', path)
            self.failed_paths.append(path)
            if AUTOPEP8_CAPABLE:
                if self.args.fix:
                    log.info('Trying to fix errors with autopep8')
                    try:
                        auto_args = [path, '--in-place',
                                     ('--max-line-length=%s' %
                                      self.args.max_line_length)]
                        if self.args.disable:
                            auto_args.append("--ignore='%s'" %
                                             self.args.disable)
                        opt_obj = autopep8.parse_args(auto_args)
                        autopep8.fix_file(path, opt_obj)
                    except Exception:
                        log.error('Unable to fix errors')
                        exc_info = sys.exc_info()
                        stacktrace.log_exc_info(exc_info, 'inspektor.style')

        return status == 0
开发者ID:tripples,项目名称:inspektor,代码行数:52,代码来源:style.py

示例14: test_autopep8_args

    def test_autopep8_args(self):
        import autopep8

        args = ['hello.py']
        us = parse_args(args)
        them = autopep8.parse_args(args)

        self.assertEqual(us.select, them.select)
        self.assertEqual(us.ignore, them.ignore)

        args = ['hello.py', '--select=E1,W1', '--ignore=W601',
                '--max-line-length', '120']
        us = parse_args(args)
        them = autopep8.parse_args(args)
        self.assertEqual(us.select, them.select)
        self.assertEqual(us.ignore, them.ignore)
        self.assertEqual(us.max_line_length, them.max_line_length)

        args = ['hello.py', '--aggressive', '-v']
        us = parse_args(args)
        them = autopep8.parse_args(args)
        self.assertEqual(us.aggressive, them.aggressive)
开发者ID:hayd,项目名称:pep8radius,代码行数:22,代码来源:test_main.py

示例15: main

def main(argv=None):
    argv = argv if argv is not None else sys.argv[1:]
    args = autopep8.parse_args(argv, apply_config=True)

    retv = 0
    for filename in args.files:
        original_contents = io.open(filename).read()
        new_contents = autopep8.fix_code(original_contents, args)
        if original_contents != new_contents:
            print('Fixing {0}'.format(filename))
            retv = 1
            with io.open(filename, 'w') as output_file:
                output_file.write(new_contents)

    return retv
开发者ID:CamZhou,项目名称:pre-commit-hooks,代码行数:15,代码来源:autopep8_wrapper.py


注:本文中的autopep8.parse_args函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。