From: Joshua Watt <jpewhacker@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Joshua Watt <JPEWhacker@gmail.com>
Subject: [OE-core][PATCH v2 25/25] scripts/contrib: Add reuse-get-license.py
Date: Wed, 15 Jul 2026 10:45:21 -0600 [thread overview]
Message-ID: <20260715164739.364323-26-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20260715164739.364323-1-JPEWhacker@gmail.com>
Adds a script that extracts the LICENSE and LIC_FILES_CHKSUM for project
that uses reuse[1].
[1]: https://reuse.software/
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
scripts/contrib/reuse-get-license.py | 106 +++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
create mode 100755 scripts/contrib/reuse-get-license.py
diff --git a/scripts/contrib/reuse-get-license.py b/scripts/contrib/reuse-get-license.py
new file mode 100755
index 0000000000..f35f13fec9
--- /dev/null
+++ b/scripts/contrib/reuse-get-license.py
@@ -0,0 +1,106 @@
+#! /usr/bin/env python3
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+# /// script
+# dependencies = [
+# "reuse",
+# "py-spdx-license",
+# ]
+# ///
+#
+# Extracts the LICENSE for software that uses reuse. Run with any PEP 723
+# complaint tool, e.g.
+#
+# uv run reuse-get-license.py <project-root>
+
+import argparse
+import hashlib
+import sys
+import textwrap
+from pathlib import Path
+
+import py_spdx_license
+import reuse.project
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Generate LICENSE expression from reuse"
+ )
+ parser.add_argument("dir", help="Project root directory", type=Path)
+ parser.add_argument(
+ "--include-submodules",
+ "-s",
+ help="Include submodules",
+ action="store_true",
+ )
+ parser.add_argument(
+ "--include-meson-subprojects",
+ "-m",
+ help="Include meson subprojects",
+ action="store_true",
+ )
+ parser.add_argument(
+ "--width",
+ "-w",
+ type=int,
+ help="Maximum line width for the output. Default is %(default)s",
+ default=100,
+ )
+
+ args = parser.parse_args()
+
+ prj = reuse.project.Project.from_directory(
+ args.dir,
+ include_submodules=args.include_submodules,
+ include_meson_subprojects=args.include_meson_subprojects,
+ )
+
+ licenses = []
+ for k in prj.licenses.keys():
+ licenses.append(py_spdx_license.parse(k))
+
+ lic = py_spdx_license.AndOp.join(licenses).sort()
+
+ prefix = 'LICENSE = "'
+
+ if args.width:
+ lic_text = textwrap.wrap(
+ f'{prefix}{lic.to_string()}"',
+ width=args.width,
+ subsequent_indent=" " * len(prefix),
+ )
+ else:
+ lic_text = [prefix + lic.to_string() + '"']
+
+ print(" \\\n".join(lic_text))
+
+ tomls = reuse.project.Project.find_global_licensing(
+ args.dir,
+ include_submodules=args.include_submodules,
+ include_meson_subprojects=args.include_meson_subprojects,
+ )
+
+ checksums = []
+
+ for t in tomls:
+ h = hashlib.md5()
+ with open(t.path, "rb") as f:
+ while b := f.read(4096):
+ h.update(b)
+
+ rel_path = Path(t.path).relative_to(args.dir)
+ checksums.append(f"file://{rel_path};md5={h.hexdigest()}")
+
+ if checksums:
+ checksums.sort()
+ prefix = 'LIC_FILES_CHKSUM = "'
+ print(prefix + (" \\\n" + " " * len(prefix)).join(checksums) + '"')
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
--
2.54.0
next prev parent reply other threads:[~2026-07-15 16:48 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 18:31 [OE-core][PATCH 00/22] Rework LICENSE to be SPDX License Expressions Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 01/22] scripts/pull-spdx-licenses.py: Add exceptions Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 02/22] Add SPDX License Exceptions Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 03/22] Add SPDX license library Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 04/22] Parse LICENSE as SPDX Expression Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 05/22] linux-firmware: Convert to SPDX license strings Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 06/22] meta-selftest: Add NO_GENERIC_LICENSE Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 07/22] convert-spdx-licenses: Convert to valid SPDX expressions Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 08/22] gcc-common.inc: Remove LICENSE Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 09/22] gcc: Update license Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 10/22] xz: Replace deprecated SPDX identifier Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 11/22] autoconf-archive: " Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 12/22] gnu-config: " Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 13/22] libglvnd: " Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 14/22] flac: " Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 15/22] libgit2: " Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 16/22] Fix up licenses Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 17/22] lib: oe: license: Rework package licenses matching Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 18/22] classes/go-mod-update-modules: Switch to SPDX license Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 19/22] license: Remove tidy_licenses() Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 20/22] meta-selftest: Change license on test recipes Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 21/22] Convert licenses to SPDX expressions Joshua Watt
2026-07-14 18:31 ` [OE-core][PATCH 22/22] meta-selftest: libxpm: Fix license Joshua Watt
2026-07-15 13:58 ` [OE-core][PATCH 00/22] Rework LICENSE to be SPDX License Expressions Mathieu Dubois-Briand
2026-07-15 16:44 ` [OE-core][PATCH v2 00/25] " Joshua Watt
2026-07-15 16:44 ` [OE-core][PATCH v2 01/25] scripts/pull-spdx-licenses.py: Add exceptions Joshua Watt
2026-07-15 16:44 ` [OE-core][PATCH v2 02/25] Add SPDX License Exceptions Joshua Watt
2026-07-15 16:44 ` [OE-core][PATCH v2 03/25] Add SPDX license library Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 04/25] Parse LICENSE as SPDX Expression Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 05/25] linux-firmware: Convert to SPDX license strings Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 06/25] meta-selftest: Add NO_GENERIC_LICENSE Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 07/25] convert-spdx-licenses: Convert to valid SPDX expressions Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 08/25] gcc-common.inc: Remove LICENSE Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 09/25] gcc: Update license Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 10/25] xz: Replace deprecated SPDX identifier Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 11/25] autoconf-archive: " Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 12/25] gnu-config: " Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 13/25] libglvnd: " Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 14/25] flac: " Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 15/25] libgit2: " Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 16/25] Fix up licenses Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 17/25] lib: oe: license: Rework package licenses matching Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 18/25] classes/go-mod-update-modules: Switch to SPDX license Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 19/25] license: Remove tidy_licenses() Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 20/25] meta-selftest: Change license on test recipes Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 21/25] Convert licenses to SPDX expressions Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 22/25] meta-selftest: libxpm: Fix license Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 23/25] lib: oe: sbom30: Handle None in Relationship Joshua Watt
2026-07-15 16:45 ` [OE-core][PATCH v2 24/25] oeqa: selftest: bbtest: Fix license exception Joshua Watt
2026-07-15 16:45 ` Joshua Watt [this message]
2026-07-15 17:11 ` [OE-core][PATCH v2 00/25] Rework LICENSE to be SPDX License Expressions Paul Barker
2026-07-15 17:56 ` Joshua Watt
2026-07-15 18:51 ` Joshua Watt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260715164739.364323-26-JPEWhacker@gmail.com \
--to=jpewhacker@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox