From ea71be48ba15fb024aa178bf774537f1a2510a7e Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Thu, 16 Jan 2025 16:49:50 +0000 Subject: [PATCH 1/5] feat(OutputHTML): Implement fallback for license references table The `--license-references` cli argument enables collection and storge of license reference data in output files. So as long as it was present as a Post-Scan option the `license_references` should not be empty. In such cases, the license reference table shall be filled with the already stored data. If however the `license_references` list is empty, the licenses should be collected from the `license_db` as a fall back, similar to the legacy license collection pre 49e7d89. Fixes #4101. Signed-off-by: Jens Keim --- src/formattedcode/output_html.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/formattedcode/output_html.py b/src/formattedcode/output_html.py index 551095fe8c..ee23ffe92a 100644 --- a/src/formattedcode/output_html.py +++ b/src/formattedcode/output_html.py @@ -188,9 +188,13 @@ def generate_output(results, license_references, version, template): """ # FIXME: This code is highly coupled with actual scans and may not # support adding new scans at all + + from licensedcode.cache import get_licenses_db + converted = {} converted_infos = {} converted_packages = {} + licenses = {} LICENSES = 'license_detections' COPYRIGHTS = 'copyrights' @@ -223,6 +227,11 @@ def generate_output(results, license_references, version, template): 'value': license_expression, }) + if not license_references and license_expression not in licenses: + license_object = get_licenses_db().get(license_expression) + if license_object != None: + licenses[license_expression] = license_object + if results: converted[path] = sorted(results, key=itemgetter('start')) @@ -239,6 +248,10 @@ def generate_output(results, license_references, version, template): if PACKAGES in scanned_file: converted_packages[path] = scanned_file[PACKAGES] + if not license_references: + licenses = dict(sorted(licenses.items())) + license_references = list(licenses.values()) + files = { 'license_copyright': converted, 'infos': converted_infos, From a5a8276f4bdc46f4539487a9e925146e66a22987 Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Mon, 14 Jul 2025 13:09:08 +0200 Subject: [PATCH 2/5] chore(Changelog): Add short description of PR#4474 changes Link Issue #4101 and Pull Request #4474. Signed-off-by: Jens Keim --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 22c4620477..0d745db06a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,11 @@ Changelog Next release -------------- +- Enable License References table for HTML Output without requiring + `--license-references` by implementing a fallback license reference + collection based on the behavior of v32.0.0. + https://github.com/aboutcode-org/scancode-toolkit/pull/4474 + https://github.com/aboutcode-org/scancode-toolkit/issues/4101 v32.4.1 - 2025-07-23 From 0d47c8e53927cceab2d697c29ce701c207092601 Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Mon, 14 Jul 2025 13:10:34 +0200 Subject: [PATCH 3/5] chore(Authors): Add my name as a contributor Signed-off-by: Jens Keim --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 3ef1709b8a..75b0533f92 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -35,6 +35,7 @@ The following organizations or individuals have contributed to ScanCode: - Horie Issei @is2ei - James Ward @jamesward - Jelmer Vernooij @jelmer +- Jens Keim @pepper-jk - Kunal Chhabra @kunalchhabra37 - Jillian Daguil @jdaguil - Jiri Popelka @jpopelka From c47bf90f913194c5c0309f247b5ef102c363e356 Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Wed, 23 Jul 2025 16:22:31 +0200 Subject: [PATCH 4/5] docs(OutputFormats): Update "License References" bullet point for HTML Signed-off-by: Jens Keim --- docs/source/cli-reference/output-format.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/cli-reference/output-format.rst b/docs/source/cli-reference/output-format.rst index bda76e4554..f7013540ae 100644 --- a/docs/source/cli-reference/output-format.rst +++ b/docs/source/cli-reference/output-format.rst @@ -406,7 +406,7 @@ Comparing Different ``json`` Output Formats - Copyright and Licenses Information - File Information - Package Information - - Licenses (Links to Dejacode/License Homepage) + - License References (SPDX ID, Links to spdx/scancode/licensedb/License Homepage) .. figure:: data/output_html1.png From 1842cadcbe0e5fd784db451a77230e62cf3895db Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Wed, 23 Jul 2025 16:24:39 +0200 Subject: [PATCH 5/5] docs(OutputFormats): Add Note for license references table `--license-references` is recommended, but mention the new fallback. Signed-off-by: Jens Keim --- docs/source/cli-reference/output-format.rst | 2 ++ .../note_snippets/output_html_license_references.rst | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 docs/source/rst_snippets/note_snippets/output_html_license_references.rst diff --git a/docs/source/cli-reference/output-format.rst b/docs/source/cli-reference/output-format.rst index f7013540ae..25ca252f31 100644 --- a/docs/source/cli-reference/output-format.rst +++ b/docs/source/cli-reference/output-format.rst @@ -408,6 +408,8 @@ Comparing Different ``json`` Output Formats - Package Information - License References (SPDX ID, Links to spdx/scancode/licensedb/License Homepage) + .. include:: /rst_snippets/note_snippets/output_html_license_references.rst + .. figure:: data/output_html1.png .. figure:: data/output_html2.png diff --git a/docs/source/rst_snippets/note_snippets/output_html_license_references.rst b/docs/source/rst_snippets/note_snippets/output_html_license_references.rst new file mode 100644 index 0000000000..c2c953c0e5 --- /dev/null +++ b/docs/source/rst_snippets/note_snippets/output_html_license_references.rst @@ -0,0 +1,4 @@ +.. note:: + + For the license references table it is recommended to pass the ``--license-references`` argument. + However, there is a fall back implemented in case the ``license_references`` data is missing.