From abe1e4748a4a2b38abfcb067861b4f50c0432112 Mon Sep 17 00:00:00 2001 From: Giacomo Tenaglia Date: Thu, 21 Nov 2024 00:03:32 +0100 Subject: [PATCH] Migrate to REUSE pre-commit checker --- .pre-commit-config.yaml | 9 ++---- ci/check_license.py | 72 ----------------------------------------- 2 files changed, 3 insertions(+), 78 deletions(-) delete mode 100755 ci/check_license.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a94d00..e0a5119 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,13 +16,10 @@ repos: - id: check-yaml - id: check-added-large-files - - repo: local + - repo: https://github.com/fsfe/reuse-tool + rev: v5.0.2 hooks: - - id: license - name: license - language: system - entry: ci/check_license.py - files: ((CMakeLists\.txt)|(\.(cpp|hpp|ipp|cu|cuh|cmake)))$ + - id: reuse - repo: https://github.com/BlankSpruce/gersemi rev: "0.17.0" diff --git a/ci/check_license.py b/ci/check_license.py deleted file mode 100755 index 6f24596..0000000 --- a/ci/check_license.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-PackageName = "covfie, a part of the ACTS project" -# SPDX-FileCopyrightText: 2022 CERN -# -# SPDX-License-Identifier: MPL-2.0 - -import argparse -import os -import sys -from subprocess import check_output -import re -import difflib -from datetime import datetime -from fnmatch import fnmatch - -EXCLUDE = [] - -def get_licence_format(file): - if file.endswith("CMakeLists.txt") or file.endswith(".cmake"): - return """# This file is part of covfie, a part of the ACTS project -# -# Copyright (c) 2022 CERN -# -# This Source Code Form is subject to the terms of the Mozilla Public License, -# v. 2.0. If a copy of the MPL was not distributed with this file, You can -# obtain one at http://mozilla.org/MPL/2.0/. -""" - elif any(file.endswith(x) for x in [".cpp",".hpp",".ipp",".cu",".cuh"]): - return """/* - * This file is part of covfie, a part of the ACTS project - * - * Copyright (c) 2022 CERN - * - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. - */ -""" - else: - raise ValueError("No license known for file `{}`".format(file)) - -def main(): - p = argparse.ArgumentParser() - p.add_argument("input", nargs="+") - p.add_argument("--exclude", "-e", action="append", default=EXCLUDE) - - args = p.parse_args() - - srcs = args.input - - exit = 0 - srcs = list(srcs) - nsrcs = len(srcs) - step = max(int(nsrcs / 20), 1) - # Iterate over all files - for i, src in enumerate(srcs): - if any([fnmatch(src, e) for e in args.exclude]): - continue - - # Read the header - with open(src, "r+") as f: - # License could not be found in header - if not f.read().startswith(get_licence_format(src)): - print("Invalid / missing license in " + src + "") - exit = 1 - continue - - sys.exit(exit) - - -if "__main__" == __name__: - main()