Skip to content

Commit 0a24921

Browse files
Fix cyclonedx unhashable type bug #3016
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 553e624 commit 0a24921

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/formattedcode/output_cyclonedx.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class CycloneDxLicenseExpression(ToDictMixin):
6161
"""
6262
expression: str = attr.ib(default=None)
6363

64+
@property
65+
def identifier(self):
66+
return self.expression
67+
6468
@classmethod
6569
def from_package(cls, package):
6670
"""
@@ -81,6 +85,10 @@ class CycloneDxProperty(ToDictMixin):
8185
name: str = attr.ib()
8286
value: str = attr.ib()
8387

88+
@property
89+
def identifier(self):
90+
return f"{self.name}-{self.value}"
91+
8492

8593
@attr.s
8694
class CycloneDxHashObject(ToDictMixin):
@@ -98,6 +106,10 @@ class CycloneDxHashObject(ToDictMixin):
98106
alg: str = attr.ib()
99107
content: str = attr.ib()
100108

109+
@property
110+
def identifier(self):
111+
return f"{self.alg}-{self.content}"
112+
101113
@classmethod
102114
def from_package(cls, package):
103115
"""
@@ -159,6 +171,10 @@ class CycloneDxExternalRef(ToDictMixin):
159171
comment: str = attr.ib(default=None)
160172
hashes: List[CycloneDxHashObject] = attr.ib(factory=list)
161173

174+
@property
175+
def identifier(self):
176+
return f"{self.url}-{self.type}-{self.comment}"
177+
162178
@classmethod
163179
def from_package(cls, package: dict):
164180
"""
@@ -428,8 +444,8 @@ def merge_lists(x, y):
428444
Merge ``y`` list items in list ``x`` avoiding duplicate entries.
429445
Return the updated ``x``.
430446
"""
431-
seen = set(x)
432-
new = (i for i in y if i not in seen)
447+
seen = set([item.identifier for item in x])
448+
new = (item for item in y if item.identifier not in seen)
433449
x.extend(new)
434450
return x
435451

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"bomFormat": "CycloneDX",
3+
"specVersion": "1.3",
4+
"version": 1,
5+
"components": [
6+
{
7+
"name": "source",
8+
"version": null,
9+
"bom-ref": "pkg:autotools/source",
10+
"group": null,
11+
"type": "library",
12+
"scope": "required",
13+
"copyright": null,
14+
"author": null,
15+
"description": null,
16+
"purl": "pkg:autotools/source",
17+
"hashes": [],
18+
"licenses": [
19+
{
20+
"expression": "LicenseRef-scancode-unicode AND FSFUL AND (FSFUL AND LicenseRef-scancode-unicode)"
21+
},
22+
{
23+
"expression": "LicenseRef-scancode-unicode"
24+
}
25+
],
26+
"externalReferences": [],
27+
"properties": [
28+
{
29+
"name": "WARNING",
30+
"value": "WARNING: component skipped in CycloneDX output: {'type': 'autotools', 'namespace': None, 'name': 'source', 'version': None, 'qualifiers': {}, 'subpath': None, 'primary_language': None, 'description': None, 'release_date': None, 'parties': [], 'keywords': [], 'homepage_url': None, 'download_url': None, 'size': None, 'sha1': None, 'md5': None, 'sha256': None, 'sha512': None, 'bug_tracking_url': None, 'code_view_url': None, 'vcs_url': None, 'copyright': None, 'declared_license_expression': 'unicode AND fsf-free AND (fsf-free AND unicode)', 'declared_license_expression_spdx': 'LicenseRef-scancode-unicode AND FSFUL AND (FSFUL AND LicenseRef-scancode-unicode)', 'license_detections': [{'license_expression': 'unicode', 'detection_log': ['from-package-file'], 'matches': [{'score': 100.0, 'start_line': 7, 'end_line': 7, 'matched_length': 10, 'match_coverage': 100.0, 'matcher': '2-aho', 'license_expression': 'unicode', 'rule_identifier': 'unicode_12.RULE', 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/unicode_12.RULE', 'matched_text': 'License & terms of use: http://www.unicode.org/copyright.html'}]}, {'license_expression': 'fsf-free', 'detection_log': ['from-package-file'], 'matches': [{'score': 100.0, 'start_line': 13, 'end_line': 14, 'matched_length': 18, 'match_coverage': 100.0, 'matcher': '2-aho', 'license_expression': 'fsf-free', 'rule_identifier': 'fsf-free.LICENSE', 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/fsf-free.LICENSE', 'matched_text': 'This configure script is free software; the Free Software Foundation\\n# gives unlimited permission to copy, distribute and modify it.'}]}, {'license_expression': 'fsf-free AND unicode', 'detection_log': ['from-package-file'], 'matches': [{'score': 100.0, 'start_line': 1587, 'end_line': 1588, 'matched_length': 18, 'match_coverage': 100.0, 'matcher': '2-aho', 'license_expression': 'fsf-free', 'rule_identifier': 'fsf-free.LICENSE', 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/fsf-free.LICENSE', 'matched_text': 'This configure script is free software; the Free Software Foundation\\ngives unlimited permission to copy, distribute and modify it.'}, {'score': 100.0, 'start_line': 1590, 'end_line': 1590, 'matched_length': 10, 'match_coverage': 100.0, 'matcher': '2-aho', 'license_expression': 'unicode', 'rule_identifier': 'unicode_12.RULE', 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/unicode_12.RULE', 'matched_text': 'License & terms of use: http://www.unicode.org/copyright.html'}]}, {'license_expression': 'fsf-free', 'detection_log': ['from-package-file'], 'matches': [{'score': 100.0, 'start_line': 8663, 'end_line': 8664, 'matched_length': 19, 'match_coverage': 100.0, 'matcher': '2-aho', 'license_expression': 'fsf-free', 'rule_identifier': 'fsf-free.RULE', 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/fsf-free.RULE', 'matched_text': 'This config.status script is free software; the Free Software Foundation\\ngives unlimited permission to copy, distribute and modify it.\"'}]}], 'other_license_expression': None, 'other_license_expression_spdx': None, 'other_license_detections': [], 'extracted_license_statement': None, 'notice_text': None, 'source_packages': [], 'extra_data': {}, 'repository_homepage_url': None, 'repository_download_url': None, 'api_data_url': None, 'package_uid': 'pkg:autotools/source?uuid=c629d8db-61d4-4d85-b222-ad9914234d67', 'datafile_paths': ['simple-icu/source/configure'], 'datasource_ids': ['autotools_configure'], 'purl': 'pkg:autotools/source'}"
31+
}
32+
]
33+
}
34+
],
35+
"dependencies": []
36+
}

0 commit comments

Comments
 (0)