How to use the autopep8.parse_args function in autopep8

To help you get started, we’ve selected a few autopep8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hhatto / autopep8 / test / test_suite.py View on Github external
def check(expected_filename, input_filename, aggressive):
    """Test and compare output.

    Return True on success.

    """
    got = autopep8.fix_file(
        input_filename,
        options=autopep8.parse_args([''] + aggressive * ['--aggressive']))

    try:
        with autopep8.open_with_encoding(expected_filename) as expected_file:
            expected = expected_file.read()
    except IOError:
        expected = None

    if expected == got:
        return True
    else:
        got_filename = expected_filename + '.err'
        encoding = autopep8.detect_encoding(input_filename)

        with autopep8.open_with_encoding(got_filename,
                                         encoding=encoding,
                                         mode='w') as got_file:
github jazzband / django-silk / silk / code_generation / django_test_client.py View on Github external
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', ''])
    )
github jdf / processing.py / mode / formatter / format_server.py View on Github external
connection, client_address = sock.accept()
    try:
        buf = b''
        while len(buf) < 4:
            buf += connection.recv(4 - len(buf))
        (size,) = unpack('>i', buf)
        if size == -1:
            #print('Format server exiting.', file=sys.stderr)
            sys.exit(0)
        src = b''
        while len(src) < size:
            src += connection.recv(4096)
        src = src.decode('utf-8')
        reformatted = autopep8.fix_code(
            src,
            options=autopep8.parse_args(['--ignore', 'E302', '']))
        encoded = reformatted.encode('utf-8')
        connection.sendall(pack('>i', len(encoded)))
        connection.sendall(encoded)
    finally:
        connection.close()
github microsoft / NimbusML / src / python / tools / code_fixer.py View on Github external
def run_autopep(filename):
    cmd_args = ['dummy', '-d']
    args = autopep8.parse_args(cmd_args)
    args.aggressive = 2
    args.in_place = True
    args.diff = False
    args.max_line_length = 66
    autopep8.fix_file(filename, args)

    if not any(x in filename for x in import_fixed) or "internal" in filename:
        isort.SortImports(filename)
        run_autoflake(filename)
github hyperspy / hyperspyUI / hyperspyui / plugincreator.py View on Github external
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
github openworm / open-worm-analysis-toolbox / temp_fix_pep8.py View on Github external
# -*- coding: utf-8 -*-
"""

"""

import glob
import os
from os import path
import autopep8 as ap

# See options at:
# https://pypi.python.org/pypi/autopep8/#usage
#-i : in place editing

options = ap.parse_args(['-i', ''])

try:
    cur_path = path.dirname(path.realpath(__file__))
except NameError:
    # ASSUMES IN ROOT PATH - i.e. that wormpy package is in this folder
    cur_path = os.getcwd()

wormpy_path = path.join(cur_path, 'wormpy')
stats_path  = path.join(wormpy_path,'stats')

print(wormpy_path)

wormpy_files = glob.glob(path.join(wormpy_path, '*.py'))
root_files = glob.glob(path.join(cur_path, '*.py'))
stats_files = glob.glob(path.join(stats_path, '*.py'))
github evhub / coconut / coconut / parser.py View on Github external
def autopep8(self, arglist=[]):
        """Enables autopep8 integration."""
        import autopep8
        args = autopep8.parse_args([""]+arglist)
        def pep8_fixer(code, **kwargs):
            """Automatic PEP8 fixer."""
            return autopep8.fix_code(code, options=args)
        self.postprocs.append(pep8_fixer)
github awesto / cookiecutter-django-shop / hooks / post_gen_project.py View on Github external
def reformat_white_space():
    try:
        import autopep8
    except ImportError:
        print(WARNING + "Could not find 'autopep8', exceeding whitespace will not be removed!" + TERMINATOR)
        return

    merchant_dir_path = os.path.abspath("./{{ cookiecutter.app_name }}")
    args = autopep8.parse_args(['--max-line-length 119', '--in-place', '--recursive'])
    if os.path.exists(merchant_dir_path):
        autopep8.fix_multiple_files([merchant_dir_path], args)