Skip to content

Commit 232f442

Browse files
Merge pull request #3402 from nexB/fix-extracted-license-statement
Format extracted_license_statement as YAML
2 parents 7b2a7de + 3ce9efc commit 232f442

File tree

302 files changed

+6278
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+6278
-398
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ License detection:
135135
These expressions are parallel to detections.
136136

137137
- The ``declared_license`` attribute is renamed ``extracted_license_statement``
138-
and is now a YAML-encoded string.
138+
and is now a YAML-encoded string, which can be parsed to recreate the
139+
original extracted license statement. Previously this used to be nested
140+
python objects lists/dicts/string, but now this is always a YAML string.
139141

140142
See `license updates documentation <https://scancode-toolkit.readthedocs.io/en/latest/explanations/license-detection-reference.html#change-in-license-data-format-package>`_
141143
for examples and details.

src/packagedcode/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import attr
1717
from packageurl import normalize_qualifiers
1818
from packageurl import PackageURL
19+
import saneyaml
1920

2021
from commoncode import filetype
2122
from commoncode.datautils import choices
@@ -780,7 +781,7 @@ def populate_license_fields(self):
780781
)
781782

782783
if self.extracted_license_statement and not isinstance(self.extracted_license_statement, str):
783-
self.extracted_license_statement = repr(self.extracted_license_statement)
784+
self.extracted_license_statement = saneyaml.dump(self.extracted_license_statement)
784785

785786
def to_dict(self, with_details=True, **kwargs):
786787
mapping = super().to_dict(with_details=with_details, **kwargs)

src/scancode/cli_test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ def check_jsonlines_scan(
340340
regen=False,
341341
remove_file_date=False,
342342
check_headers=False,
343+
remove_uuid=True,
343344
):
344345
"""
345346
Check the scan result_file JSON Lines results against the expected_file
@@ -352,6 +353,9 @@ def check_jsonlines_scan(
352353
with io.open(result_file, encoding='utf-8') as res:
353354
results = [json.loads(line) for line in res]
354355

356+
if remove_uuid:
357+
for result in results:
358+
result = remove_uuid_from_scan(result)
355359
streamline_jsonlines_scan(results, remove_file_date)
356360

357361
if regen:
@@ -360,6 +364,9 @@ def check_jsonlines_scan(
360364

361365
with io.open(expected_file, encoding='utf-8') as res:
362366
expected = json.load(res)
367+
if remove_uuid:
368+
for result in results:
369+
result = remove_uuid_from_scan(result)
363370

364371
streamline_jsonlines_scan(expected, remove_file_date)
365372

0 commit comments

Comments
 (0)