|
26 | 26 | # See https://github.com/package-url/packageurl-python/issues/65
|
27 | 27 | from packageurl import PackageURL # type: ignore
|
28 | 28 |
|
29 |
| -from . import AttachedText, ExternalReference, HashAlgorithm, HashType, LicenseChoice, OrganizationalEntity, Property, \ |
30 |
| - sha1sum, XsUri, IdentifiableAction, Copyright |
| 29 | +from . import AttachedText, Copyright, ExternalReference, HashAlgorithm, HashType, IdentifiableAction, LicenseChoice, \ |
| 30 | + OrganizationalEntity, Property, sha1sum, XsUri |
31 | 31 | from .issue import IssueType
|
32 | 32 | from .release_note import ReleaseNotes
|
33 | 33 | from .vulnerability import Vulnerability
|
@@ -151,6 +151,11 @@ class ComponentEvidence:
|
151 | 151 |
|
152 | 152 | def __init__(self, licenses: Optional[List[LicenseChoice]] = None,
|
153 | 153 | copyright_: Optional[List[Copyright]] = None) -> None:
|
| 154 | + if not licenses and not copyright_: |
| 155 | + raise NoPropertiesProvidedException( |
| 156 | + 'At least one of `licenses` or `copyright_` must be supplied for a `ComponentEvidence`.' |
| 157 | + ) |
| 158 | + |
154 | 159 | self.licenses = licenses
|
155 | 160 | self.copyright = copyright_
|
156 | 161 |
|
@@ -372,7 +377,10 @@ def __eq__(self, other: object) -> bool:
|
372 | 377 | return False
|
373 | 378 |
|
374 | 379 | def __hash__(self) -> int:
|
375 |
| - return hash((hash(self.type), hash(self.diff), str(self.resolves))) |
| 380 | + return hash(( |
| 381 | + hash(self.type), hash(self.diff), |
| 382 | + tuple([hash(issue) for issue in set(self.resolves)]) if self.resolves else None |
| 383 | + )) |
376 | 384 |
|
377 | 385 | def __repr__(self) -> str:
|
378 | 386 | return f'<Patch type={self.type}, id={id(self)}>'
|
@@ -559,7 +567,11 @@ def __eq__(self, other: object) -> bool:
|
559 | 567 |
|
560 | 568 | def __hash__(self) -> int:
|
561 | 569 | return hash((
|
562 |
| - str(self.ancestors), str(self.descendants), str(self.variants), str(self.commits), str(self.patches), |
| 570 | + tuple([hash(ancestor) for ancestor in set(self.ancestors)]) if self.ancestors else None, |
| 571 | + tuple([hash(descendant) for descendant in set(self.descendants)]) if self.descendants else None, |
| 572 | + tuple([hash(variant) for variant in set(self.variants)]) if self.variants else None, |
| 573 | + tuple([hash(commit) for commit in set(self.commits)]) if self.commits else None, |
| 574 | + tuple([hash(patch) for patch in set(self.patches)]) if self.patches else None, |
563 | 575 | self.notes
|
564 | 576 | ))
|
565 | 577 |
|
@@ -1220,9 +1232,15 @@ def __eq__(self, other: object) -> bool:
|
1220 | 1232 |
|
1221 | 1233 | def __hash__(self) -> int:
|
1222 | 1234 | return hash((
|
1223 |
| - self.author, self.copyright, self.description, str(self.external_references), self.group, |
1224 |
| - str(self.hashes), str(self.licenses), self.mime_type, self.name, str(self.properties), self.publisher, |
1225 |
| - self.purl, self.release_notes, self.scope, self.supplier, self.type, self.version, self.cpe |
| 1235 | + self.type, self.mime_type, self.supplier, self.author, self.publisher, self.group, self.name, |
| 1236 | + self.version, self.description, self.scope, |
| 1237 | + tuple([hash(hash_) for hash_ in set(self.hashes)]) if self.hashes else None, |
| 1238 | + tuple([hash(license_) for license_ in set(self.licenses)]) if self.licenses else None, |
| 1239 | + self.copyright, self.cpe, self.purl, self.swid, self.pedigree, |
| 1240 | + tuple([hash(ref) for ref in set(self.external_references)]) if self.external_references else None, |
| 1241 | + tuple([hash(prop) for prop in set(self.properties)]) if self.properties else None, |
| 1242 | + tuple([hash(component) for component in set(self.components)]) if self.components else None, |
| 1243 | + self.evidence, self.release_notes |
1226 | 1244 | ))
|
1227 | 1245 |
|
1228 | 1246 | def __repr__(self) -> str:
|
|
0 commit comments