[elbe-devel] [PATCH 2/2] treewide: validate SPDX headers
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Mon Jul 8 15:10:54 CEST 2024
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
setup.cfg | 5 +++++
tests/flake8/spdx.py | 26 ++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/setup.cfg b/setup.cfg
index 24875da04911..bca146dd7024 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -6,3 +6,8 @@ extend-exclude =
debian/,
initvm/
application-import-names = elbepack elbevalidate
+
+[flake8:local-plugins]
+extension =
+ SP1 = tests.flake8.spdx:SPDXChecker
+paths = .
diff --git a/tests/flake8/spdx.py b/tests/flake8/spdx.py
new file mode 100644
index 000000000000..50f8d58a9557
--- /dev/null
+++ b/tests/flake8/spdx.py
@@ -0,0 +1,26 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# SPDX-License-Identifier: GPL-3.0-or-later
+# SPDX-FileCopyrightText: 2024 Linutronix GmbH
+
+class SPDXChecker:
+ def __init__(self, tree, lines):
+ self.lines = lines
+
+ def run(self):
+ lines = list(self.lines)
+
+ if not lines:
+ return
+
+ if lines[0].startswith('#!'):
+ lines.pop(0)
+
+ if lines[0] == '\n':
+ lines.pop(0)
+
+ if len(lines) < 4 or \
+ lines[0] != '# ELBE - Debian Based Embedded Rootfilesystem Builder\n' or \
+ lines[1] != '# SPDX-License-Identifier: GPL-3.0-or-later\n' or \
+ not lines[2].startswith('# SPDX-FileCopyrightText: '):
+
+ yield 1, 0, 'SP1 invalid copyright header', type(self)
--
2.45.2
More information about the elbe-devel
mailing list