Beispiel #1
0
def checkCopyrightForAll():
    """
    Checks for copyright headers in all the modified files. In case of local
    repo, this script will just look for uncommitted files and in case of CI
    it compares between branches "$PR_TARGET_BRANCH" and "current-pr-branch"
    """
    argparser = argparse.ArgumentParser(
        "Checks for a consistent copyright header in git's modified files")
    argparser.add_argument("--update-current-year",
                           dest='update_current_year',
                           action="store_true",
                           required=False,
                           help="If set, "
                           "update the current year if a header is already "
                           "present and well formatted.")
    args = argparser.parse_args()
    files = gitutils.modifiedFiles(filter=checkThisFile)
    errors = []
    for f in files:
        errors += checkCopyright(f, args.update_current_year)
    if len(errors) > 0:
        print("Copyright headers incomplete in some of the files!")
        for e in errors:
            print("  %s:%d Issue: %s" % (e[0], e[1], e[2]))
        print("")
        n_fixable = sum(1 for e in errors if e[-1] is not None)
        path_parts = os.path.abspath(__file__).split(os.sep)
        file_from_cuml = os.sep.join(path_parts[path_parts.index("ci"):])
        if n_fixable > 0:
            print("You can run {} --update-current-year to fix {} of these "
                  "errors.\n".format(file_from_cuml, n_fixable))
        raise Exception("Copyright check failed! Check above to know more.")
    else:
        print("Copyright check passed")
Beispiel #2
0
def checkCopyright_main():
    """
    Checks for copyright headers in all the modified files. In case of local
    repo, this script will just look for uncommitted files and in case of CI
    it compares between branches "$PR_TARGET_BRANCH" and "current-pr-branch"
    """
    retVal = 0

    argparser = argparse.ArgumentParser(
        "Checks for a consistent copyright header in git's modified files")
    argparser.add_argument("--update-current-year",
                           dest='update_current_year',
                           action="store_true",
                           required=False,
                           help="If set, "
                           "update the current year if a header is already "
                           "present and well formatted.")
    argparser.add_argument("--git-modified-only",
                           dest='git_modified_only',
                           action="store_true",
                           required=False,
                           help="If set, "
                           "only files seen as modified by git will be "
                           "processed.")

    (args, dirs) = argparser.parse_known_args()
    if args.git_modified_only:
        files = gitutils.modifiedFiles(pathFilter=checkThisFile)
    else:
        files = []
        for d in [os.path.abspath(d) for d in dirs]:
            if not (os.path.isdir(d)):
                raise ValueError(f"{d} is not a directory.")
            files += getAllFilesUnderDir(d, pathFilter=checkThisFile)

    errors = []
    for f in files:
        errors += checkCopyright(f, args.update_current_year)

    if len(errors) > 0:
        print("Copyright headers incomplete in some of the files!")
        for e in errors:
            print("  %s:%d Issue: %s" % (e[0], e[1], e[2]))
        print("")
        n_fixable = sum(1 for e in errors if e[-1] is not None)
        path_parts = os.path.abspath(__file__).split(os.sep)
        file_from_repo = os.sep.join(path_parts[path_parts.index("ci"):])
        if n_fixable > 0:
            print(("You can run `python {} --git-modified-only "
                   "--update-current-year` to fix {} of these "
                   "errors.\n").format(file_from_repo, n_fixable))
        retVal = 1
    else:
        print("Copyright check passed")

    return retVal
def listAllChangedFiles(fileRegex, dstdir, inplace):
    allFiles = []

    def checkThisFile(f):
        return True if fileRegex.search(f) else False

    files = gitutils.modifiedFiles(filter=checkThisFile)
    for f in files:
        dst = f if inplace else os.path.join(dstdir, f)
        allFiles.append((f, dst))
    return allFiles
def checkCopyrightForAll():
    """
    Checks for copyright headers in all the modified files. In case of local
    repo, this script will just look for uncommitted files and in case of CI
    it compares between branches "$PR_TARGET_BRANCH" and "current-pr-branch"
    """
    files = gitutils.modifiedFiles(filter=checkThisFile)
    errors = []
    for f in files:
        errors += checkCopyright(f)
    if len(errors) > 0:
        print("Copyright headers incomplete in some of the files!")
        for e in errors:
            print("  %s:%d Issue: %s" % (e[0], e[1], e[2]))
        print("")
        raise Exception("Copyright check failed! Check above to know more")
    else:
        print("Copyright check passed")