|
1 | 1 | # SPDX-FileCopyrightText: 2022 spdx contributors |
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | +from dataclasses import astuple |
| 5 | + |
4 | 6 | from beartype.typing import Dict, List, Optional, Set |
5 | 7 |
|
6 | 8 | from spdx_tools.common.typing.constructor_type_errors import ConstructorTypeErrors |
| 9 | +from spdx_tools.common.typing.dataclass_with_properties import freeze_dataclass_with_properties_list |
7 | 10 | from spdx_tools.spdx.model import Relationship, RelationshipType |
8 | 11 | from spdx_tools.spdx.parser.error import SPDXParsingError |
9 | 12 | from spdx_tools.spdx.parser.jsonlikedict.dict_parsing_functions import ( |
@@ -35,9 +38,12 @@ def parse_all_relationships(self, input_doc_dict: Dict) -> List[Relationship]: |
35 | 38 | document_describes: List[str] = delete_duplicates_from_list(input_doc_dict.get("documentDescribes", [])) |
36 | 39 | doc_spdx_id: Optional[str] = input_doc_dict.get("SPDXID") |
37 | 40 |
|
38 | | - existing_relationships_without_comments: Set[Relationship] = set(self.get_all_relationships_without_comments( |
39 | | - relationships |
40 | | - )) |
| 41 | + relationship_hash = lambda r: hash("{} -> {} ({})" \ |
| 42 | + .format(r.spdx_element_id, |
| 43 | + str(r.related_spdx_element_id), |
| 44 | + str(r.relationship_type))) |
| 45 | + existing_relationships_without_comments: Set[Relationship] = freeze_dataclass_with_properties_list( |
| 46 | + self.get_all_relationships_without_comments(relationships)) |
41 | 47 | relationships.extend( |
42 | 48 | parse_field_or_log_error( |
43 | 49 | self.logger, |
@@ -161,10 +167,10 @@ def check_if_relationship_exists( |
161 | 167 | self, relationship: Relationship, existing_relationships: Set[Relationship] |
162 | 168 | ) -> bool: |
163 | 169 | # assume existing relationships are stripped of comments |
164 | | - if relationship in existing_relationships: |
| 170 | + if astuple(relationship) in existing_relationships: |
165 | 171 | return True |
166 | 172 | relationship_inverted: Relationship = self.invert_relationship(relationship) |
167 | | - if relationship_inverted in existing_relationships: |
| 173 | + if astuple(relationship_inverted) in existing_relationships: |
168 | 174 | return True |
169 | 175 |
|
170 | 176 | return False |
|
0 commit comments