Python autopep8.parse_args() Examples

The following are 10 code examples of autopep8.parse_args(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module autopep8 , or try the search function .
Example #1
Source File: vfp2py.py    From vfp2py with MIT License 6 votes vote down vote up
def prg2py_after_preproc(data, parser_start, input_filename):
    input_stream = antlr4.InputStream(data)
    lexer = VisualFoxpro9Lexer(input_stream)
    stream = antlr4.CommonTokenStream(lexer)
    parser = VisualFoxpro9Parser(stream)
    tree = run_parser(stream, parser, parser_start)
    TreeCleanVisitor().visit(tree)
    output_tree = PythonConvertVisitor(input_filename).visit(tree)
    if not isinstance(output_tree, list):
        return output_tree
    output = add_indents(output_tree, 0)
    options = autopep8.parse_args(['--max-line-length', '100000', '-'])
    output = autopep8.fix_code(output, options)
    tokens = list(tokenize.generate_tokens(io.StringIO(output).readline))
    for i, token in enumerate(tokens):
        token = list(token)
        if token[0] == tokenize.STRING and token[1].startswith('u'):
            token[1] = token[1][1:]
        tokens[i] = tuple(token)
    return tokenize.untokenize(tokens) 
Example #2
Source File: pavement.py    From qgis-geoserver-plugin with GNU General Public License v2.0 6 votes vote down vote up
def autopep8(args):
    """Format code according to PEP8
    """
    try:
        import autopep8
    except:
        error('autopep8 not found! Run "paver install_devtools".')
        sys.exit(1)

    if any(x not in args for x in ['-i', '--in-place']):
        args.append('-i')

    args.append('--ignore=E261,E265,E402,E501')
    args.insert(0, 'dummy')

    cmd_args = autopep8.parse_args(args)

    excludes = ('ext-lib', 'ext-src')
    for p in options.plugin.source_dir.walk():
        if any(exclude in p for exclude in excludes):
            continue

        if p.fnmatch('*.py'):
            autopep8.fix_file(p, options=cmd_args) 
Example #3
Source File: test_main.py    From pep8radius with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: django_test_client.py    From django-silk with MIT License 5 votes vote down vote up
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', ''])
    ) 
Example #5
Source File: django_test_client.py    From django-silk with MIT License 5 votes vote down vote up
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', ''])
    ) 
Example #6
Source File: test_main.py    From pep8radius with MIT License 5 votes vote down vote up
def test_no_config(self):
        args_before = parse_args(apply_config=False, root=TEMP_DIR)
        self.assertNotIn('E999', args_before.ignore) 
Example #7
Source File: test_main.py    From pep8radius with MIT License 5 votes vote down vote up
def test_global_config(self):
        with open(GLOBAL_CONFIG, mode='w') as f:
            f.write("[pep8]\nignore=E999")
        args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG],
                                apply_config=True, root=TEMP_DIR)
        self.assertIn('E999', args_after.ignore)
        args_after = parse_args(['--global-config=False'],
                                apply_config=True, root=TEMP_DIR)
        self.assertNotIn('E999', args_after.ignore) 
Example #8
Source File: test_main.py    From pep8radius with MIT License 5 votes vote down vote up
def test_local_config(self):
        with open(LOCAL_CONFIG, mode='w') as f:
            f.write("[pep8]\nignore=E999")
        args_after = parse_args([''],
                                apply_config=True, root=TEMP_DIR)
        self.assertIn('E999', args_after.ignore)
        args_after = parse_args(['--ignore-local-config'],
                                apply_config=True, root=TEMP_DIR)
        self.assertNotIn('E999', args_after.ignore) 
Example #9
Source File: test_main.py    From pep8radius with MIT License 5 votes vote down vote up
def test_local_and_global_config(self):
        with open(GLOBAL_CONFIG, mode='w') as f:
            f.write("[pep8]\nindent-size=2")
        with open(LOCAL_CONFIG, mode='w') as f:
            f.write("[pep8]\nindent-size=3")
        args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG],
                                apply_config=True, root=TEMP_DIR)
        self.assertEqual(3, args_after.indent_size)
        args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG,
                                 '--ignore-local-config'],
                                apply_config=True, root=TEMP_DIR)
        self.assertEqual(2, args_after.indent_size) 
Example #10
Source File: test_infra.py    From operator with Apache License 2.0 5 votes vote down vote up
def test_pep8(self):
        # verify all files are nicely styled
        python_filepaths = get_python_filepaths()
        style_guide = get_style_guide()
        fake_stdout = io.StringIO()
        with patch('sys.stdout', fake_stdout):
            report = style_guide.check_files(python_filepaths)

        # if flake8 didnt' report anything, we're done
        if report.total_errors == 0:
            return

        # grab on which files we have issues
        flake8_issues = fake_stdout.getvalue().split('\n')
        broken_filepaths = {item.split(':')[0] for item in flake8_issues if item}

        # give hints to the developer on how files' style could be improved
        options = autopep8.parse_args([''])
        options.aggressive = 1
        options.diff = True
        options.max_line_length = 99

        issues = []
        for filepath in broken_filepaths:
            diff = autopep8.fix_file(filepath, options=options)
            if diff:
                issues.append(diff)

        report = ["Please fix files as suggested by autopep8:"] + issues
        report += ["\n-- Original flake8 reports:"] + flake8_issues
        self.fail("\n".join(report))