Пример #1
0
def pep8radius_main(args, vc=None, cwd=TEMP_DIR, apply_config=False):
    with from_dir(cwd):
        with captured_output() as (out, err):
            try:
                from pep8radius.main import main
                main(args, vc=vc, apply_config=apply_config, cwd=cwd)
            except SystemExit:
                pass
        return out.getvalue().strip()
Пример #2
0
def pep8radius_main(args, vc=None, cwd=TEMP_DIR, apply_config=False):
    with from_dir(cwd):
        with captured_output() as (out, err):
            try:
                from pep8radius.main import main
                main(args, vc=vc, apply_config=apply_config, cwd=cwd)
            except SystemExit:
                pass
        return out.getvalue().strip()
Пример #3
0
def fix_file(file_name,
             line_ranges,
             options=None,
             in_place=False,
             diff=False,
             verbose=0,
             cwd=None):
    """Calls fix_code on the source code from the passed in file over the given
    line_ranges.

    - If diff then this returns the udiff for the changes, otherwise
    returns the fixed code.
    - If in_place the changes are written to the file.

    """
    import codecs
    from os import getcwd
    from pep8radius.diff import get_diff
    from pep8radius.shell import from_dir

    if cwd is None:
        cwd = getcwd()

    with from_dir(cwd):
        try:
            with codecs.open(file_name, 'r', encoding='utf-8') as f:
                original = f.read()
        except IOError:
            # Most likely the file has been removed.
            # Note: it would be nice if we could raise here, specifically
            # for the case of passing in a diff when in the wrong directory.
            return ''

    fixed = fix_code(original, line_ranges, options, verbose=verbose)

    if in_place:
        with from_dir(cwd):
            with codecs.open(file_name, 'w', encoding='utf-8') as f:
                f.write(fixed)

    return get_diff(original, fixed, file_name) if diff else fixed
Пример #4
0
def fix_file(file_name, line_ranges, options=None, in_place=False,
             diff=False, verbose=0, cwd=None):
    """Calls fix_code on the source code from the passed in file over the given
    line_ranges.

    - If diff then this returns the udiff for the changes, otherwise
    returns the fixed code.
    - If in_place the changes are written to the file.

    """
    import codecs
    from os import getcwd
    from pep8radius.diff import get_diff
    from pep8radius.shell import from_dir

    if cwd is None:
        cwd = getcwd()

    with from_dir(cwd):
        try:
            with codecs.open(file_name, 'r', encoding='utf-8') as f:
                original = f.read()
        except IOError:
            # Most likely the file has been removed.
            # Note: it would be nice if we could raise here, specifically
            # for the case of passing in a diff when in the wrong directory.
            return ''

    fixed = fix_code(original, line_ranges, options, verbose=verbose)

    if in_place:
        with from_dir(cwd):
            with codecs.open(file_name, 'w', encoding='utf-8') as f:
                f.write(fixed)

    return get_diff(original, fixed, file_name) if diff else fixed
Пример #5
0
def save(contents, f, cwd=TEMP_DIR):
    with from_dir(cwd):
        with open(f, 'w') as f1:
            f1.write(contents)
Пример #6
0
def save(contents, f, cwd=TEMP_DIR):
    with from_dir(cwd):
        with open(f, 'w') as f1:
            f1.write(contents)