Beispiel #1
0
def run_by_file_only(repo,
                     file_or_directory,
                     recurse=True,
                     dryrun=False,
                     verbose=False,
                     autopep8=None,
                     errors=None):
    select_opt = (["--select={0}".format(",".join(errors))]
                  if errors != ERRORS else [])
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"
                    ] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Beispiel #2
0
def run_autopep8(repo,
                 file_or_directory,
                 recurse=True,
                 dryrun=False,
                 verbose=False,
                 autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Beispiel #3
0
def run_by_file_only(repo,
                     file_or_directory, recurse=True,
                     dryrun=False, verbose=False, autopep8=None,
                     errors=None):
    select_opt = (
        ["--select={0}".format(",".join(errors))]
        if errors != ERRORS
        else []
    )
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Beispiel #4
0
def run_autopylint(file_or_directory, ext=".py", recurse=True,
                   dryrun=False, verbose=False, author=None):
    file_list = get_filelist(file_or_directory, recurse, ext)
    i = 0
    for fullpath, hash_before, error_no, error_comment in loop_params(file_list):
        cmd = ["autopylint", "--in-place", "--verbose",
               "--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if hash_before != sha1_file(fullpath):
                # I can't tell if autopep8 has modified a file from the return code,
                # so I do it the hard way...
                info(output)
                git_commit(
                    fullpath,
                    "{0} {1}".format(error_no, error_comment),
                    dryrun, verbose, author)
                i += 1
    info("# {0} files scanned/modified".format(i))
Beispiel #5
0
def run_autopep8(repo,
                 file_or_directory, recurse=True,
                 dryrun=False, verbose=False, autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))