21
21
from typing import Iterable , Optional , Set
22
22
from uuid import UUID , uuid4
23
23
24
+ from sortedcontainers import SortedSet
25
+
24
26
from ..exception .model import UnknownComponentDependencyException
25
27
from ..parser import BaseParser
26
28
from . import ExternalReference , LicenseChoice , OrganizationalContact , OrganizationalEntity , Property , ThisTool , Tool
@@ -43,13 +45,13 @@ def __init__(self, *, tools: Optional[Iterable[Tool]] = None,
43
45
licenses : Optional [Iterable [LicenseChoice ]] = None ,
44
46
properties : Optional [Iterable [Property ]] = None ) -> None :
45
47
self .timestamp = datetime .now (tz = timezone .utc )
46
- self .tools = set (tools or [])
47
- self .authors = set (authors or [])
48
+ self .tools = SortedSet (tools or [])
49
+ self .authors = SortedSet (authors or [])
48
50
self .component = component
49
51
self .manufacture = manufacture
50
52
self .supplier = supplier
51
- self .licenses = set (licenses or [])
52
- self .properties = set (properties or [])
53
+ self .licenses = SortedSet (licenses or [])
54
+ self .properties = SortedSet (properties or [])
53
55
54
56
if not tools :
55
57
self .tools .add (ThisTool )
@@ -69,7 +71,7 @@ def timestamp(self, timestamp: datetime) -> None:
69
71
self ._timestamp = timestamp
70
72
71
73
@property
72
- def tools (self ) -> Set [Tool ]:
74
+ def tools (self ) -> SortedSet [Tool ]:
73
75
"""
74
76
Tools used to create this BOM.
75
77
@@ -80,10 +82,10 @@ def tools(self) -> Set[Tool]:
80
82
81
83
@tools .setter
82
84
def tools (self , tools : Iterable [Tool ]) -> None :
83
- self ._tools = set (tools )
85
+ self ._tools = SortedSet (tools )
84
86
85
87
@property
86
- def authors (self ) -> Set [OrganizationalContact ]:
88
+ def authors (self ) -> SortedSet [OrganizationalContact ]:
87
89
"""
88
90
The person(s) who created the BOM.
89
91
@@ -98,7 +100,7 @@ def authors(self) -> Set[OrganizationalContact]:
98
100
99
101
@authors .setter
100
102
def authors (self , authors : Iterable [OrganizationalContact ]) -> None :
101
- self ._authors = set (authors )
103
+ self ._authors = SortedSet (authors )
102
104
103
105
@property
104
106
def component (self ) -> Optional [Component ]:
@@ -155,7 +157,7 @@ def supplier(self, supplier: Optional[OrganizationalEntity]) -> None:
155
157
self ._supplier = supplier
156
158
157
159
@property
158
- def licenses (self ) -> Set [LicenseChoice ]:
160
+ def licenses (self ) -> SortedSet [LicenseChoice ]:
159
161
"""
160
162
A optional list of statements about how this BOM is licensed.
161
163
@@ -166,10 +168,10 @@ def licenses(self) -> Set[LicenseChoice]:
166
168
167
169
@licenses .setter
168
170
def licenses (self , licenses : Iterable [LicenseChoice ]) -> None :
169
- self ._licenses = set (licenses )
171
+ self ._licenses = SortedSet (licenses )
170
172
171
173
@property
172
- def properties (self ) -> Set [Property ]:
174
+ def properties (self ) -> SortedSet [Property ]:
173
175
"""
174
176
Provides the ability to document properties in a key/value store. This provides flexibility to include data not
175
177
officially supported in the standard without having to use additional namespaces or create extensions.
@@ -184,7 +186,7 @@ def properties(self) -> Set[Property]:
184
186
185
187
@properties .setter
186
188
def properties (self , properties : Iterable [Property ]) -> None :
187
- self ._properties = set (properties )
189
+ self ._properties = SortedSet (properties )
188
190
189
191
def __eq__ (self , other : object ) -> bool :
190
192
if isinstance (other , BomMetaData ):
@@ -237,9 +239,9 @@ def __init__(self, *, components: Optional[Iterable[Component]] = None,
237
239
"""
238
240
self .uuid = uuid4 ()
239
241
self .metadata = BomMetaData ()
240
- self .components = set (components or [])
241
- self .services = set (services or [])
242
- self .external_references = set (external_references or [])
242
+ self .components = SortedSet (components or [])
243
+ self .services = SortedSet (services or [])
244
+ self .external_references = SortedSet (external_references or [])
243
245
244
246
@property
245
247
def uuid (self ) -> UUID :
@@ -273,7 +275,7 @@ def metadata(self, metadata: BomMetaData) -> None:
273
275
self ._metadata = metadata
274
276
275
277
@property
276
- def components (self ) -> Set [Component ]:
278
+ def components (self ) -> SortedSet [Component ]:
277
279
"""
278
280
Get all the Components currently in this Bom.
279
281
@@ -284,7 +286,7 @@ def components(self) -> Set[Component]:
284
286
285
287
@components .setter
286
288
def components (self , components : Iterable [Component ]) -> None :
287
- self ._components = set (components )
289
+ self ._components = SortedSet (components )
288
290
289
291
def get_component_by_purl (self , purl : Optional [str ]) -> Optional [Component ]:
290
292
"""
@@ -327,7 +329,7 @@ def has_component(self, component: Component) -> bool:
327
329
return component in self .components
328
330
329
331
@property
330
- def services (self ) -> Set [Service ]:
332
+ def services (self ) -> SortedSet [Service ]:
331
333
"""
332
334
Get all the Services currently in this Bom.
333
335
@@ -338,10 +340,10 @@ def services(self) -> Set[Service]:
338
340
339
341
@services .setter
340
342
def services (self , services : Iterable [Service ]) -> None :
341
- self ._services = set (services )
343
+ self ._services = SortedSet (services )
342
344
343
345
@property
344
- def external_references (self ) -> Set [ExternalReference ]:
346
+ def external_references (self ) -> SortedSet [ExternalReference ]:
345
347
"""
346
348
Provides the ability to document external references related to the BOM or to the project the BOM describes.
347
349
@@ -352,7 +354,7 @@ def external_references(self) -> Set[ExternalReference]:
352
354
353
355
@external_references .setter
354
356
def external_references (self , external_references : Iterable [ExternalReference ]) -> None :
355
- self ._external_references = set (external_references )
357
+ self ._external_references = SortedSet (external_references )
356
358
357
359
def has_vulnerabilities (self ) -> bool :
358
360
"""
0 commit comments