Skip to content

Commit 83aa0c2

Browse files
committed
wip
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 4778a11 commit 83aa0c2

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

cyclonedx/model/component.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,52 +1741,35 @@ def get_pypi_url(self) -> str:
17411741
else:
17421742
return f'https://pypi.org/project/{self.name}'
17431743

1744+
@staticmethod
1745+
def __comparable_tuple(o: 'Component') -> _ComparableTuple:
1746+
return _ComparableTuple((
1747+
o._bom_ref, # see https://github.com/CycloneDX/cyclonedx-python-lib/issues/753
1748+
o.type, o.group, o.name, o.version,
1749+
o.mime_type, o.supplier, o.author, o.publisher,
1750+
o.description, o.scope, _ComparableTuple(o.hashes),
1751+
_ComparableTuple(o.licenses), o.copyright, o.cpe,
1752+
None if o.purl is None else _ComparablePackageURL(o.purl),
1753+
o.swid, o.pedigree,
1754+
_ComparableTuple(o.external_references), _ComparableTuple(o.properties),
1755+
_ComparableTuple(o.components), o.evidence, o.release_notes, o.modified,
1756+
_ComparableTuple(o.authors), _ComparableTuple(o.omnibor_ids), o.manufacturer,
1757+
_ComparableTuple(o.swhids), o.crypto_properties, _ComparableTuple(o.tags),
1758+
))
1759+
17441760
def __eq__(self, other: object) -> bool:
17451761
if isinstance(other, Component):
1746-
return hash(other) == hash(self)
1762+
return self.__comparable_tuple(other) == self.__comparable_tuple(self)
17471763
return False
17481764

17491765
def __lt__(self, other: Any) -> bool:
17501766
if isinstance(other, Component):
1751-
return _ComparableTuple((
1752-
self.type, self.group, self.name, self.version,
1753-
self.mime_type, self.supplier, self.author, self.publisher,
1754-
self.description, self.scope, _ComparableTuple(self.hashes),
1755-
_ComparableTuple(self.licenses), self.copyright, self.cpe,
1756-
None if self.purl is None else _ComparablePackageURL(self.purl),
1757-
self.swid, self.pedigree,
1758-
_ComparableTuple(self.external_references), _ComparableTuple(self.properties),
1759-
_ComparableTuple(self.components), self.evidence, self.release_notes, self.modified,
1760-
_ComparableTuple(self.authors), _ComparableTuple(self.omnibor_ids), self.manufacturer,
1761-
_ComparableTuple(self.swhids), self.crypto_properties, _ComparableTuple(self.tags)
1762-
)) < _ComparableTuple((
1763-
other.type, other.group, other.name, other.version,
1764-
other.mime_type, other.supplier, other.author, other.publisher,
1765-
other.description, other.scope, _ComparableTuple(other.hashes),
1766-
_ComparableTuple(other.licenses), other.copyright, other.cpe,
1767-
None if other.purl is None else _ComparablePackageURL(other.purl),
1768-
other.swid, other.pedigree,
1769-
_ComparableTuple(other.external_references), _ComparableTuple(other.properties),
1770-
_ComparableTuple(other.components), other.evidence, other.release_notes, other.modified,
1771-
_ComparableTuple(other.authors), _ComparableTuple(other.omnibor_ids), other.manufacturer,
1772-
_ComparableTuple(other.swhids), other.crypto_properties, _ComparableTuple(other.tags)
1773-
))
1767+
return self.__comparable_tuple(self) < self.__comparable_tuple(other)
17741768
return NotImplemented
17751769

17761770
def __hash__(self) -> int:
1777-
return hash((
1778-
self.type, self.group, self.name, self.version,
1779-
self.mime_type, self.supplier, self.author, self.publisher,
1780-
self.description, self.scope, tuple(self.hashes),
1781-
tuple(self.licenses), self.copyright, self.cpe,
1782-
self.purl, self.bom_ref.value,
1783-
self.swid, self.pedigree,
1784-
tuple(self.external_references), tuple(self.properties),
1785-
tuple(self.components), self.evidence, self.release_notes, self.modified,
1786-
tuple(self.authors), tuple(self.omnibor_ids), self.manufacturer,
1787-
tuple(self.swhids), self.crypto_properties, tuple(self.tags)
1788-
))
1771+
return hash(self.__comparable_tuple(self))
17891772

17901773
def __repr__(self) -> str:
17911774
return f'<Component bom-ref={self.bom_ref!r}, group={self.group}, name={self.name}, ' \
1792-
f'version={self.version}, type={self.type}>'
1775+
f'version={self.version}, type={self.type}>'

0 commit comments

Comments
 (0)