Skip to content

Commit b2d174e

Browse files
committed
Rename Tool* to Tools*
Also fixed an import Need to fix an circular import still...
1 parent da66f6b commit b2d174e

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

cyclonedx/model/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
SchemaVersion1Dot5,
5151
SchemaVersion1Dot6,
5252
)
53-
53+
from .tool import Tool
5454

5555
@serializable.serializable_enum
5656
class DataFlow(str, Enum):
@@ -1196,7 +1196,6 @@ def __hash__(self) -> int:
11961196
def __repr__(self) -> str:
11971197
return f'<Copyright text={self.text}>'
11981198

1199-
12001199
ThisTool = Tool(
12011200
vendor='CycloneDX',
12021201
name='cyclonedx-python-lib',

cyclonedx/model/bom.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
MutuallyExclusivePropertiesException,
3232
UnknownComponentDependencyException,
3333
)
34-
from ..model.tool import Tool, ToolRepository, ToolRepositoryHelper
34+
from ..model.tool import Tool, ToolsRepository, ToolsRepositoryHelper
3535
from ..schema.schema import (
3636
SchemaVersion1Dot0,
3737
SchemaVersion1Dot1,
@@ -74,7 +74,7 @@ def __init__(self, *, tools: Optional[Union[Iterable[Tool], Dict[AnyStr, Any]]]
7474
# Deprecated as of v1.6
7575
manufacture: Optional[OrganizationalEntity] = None) -> None:
7676
self.timestamp = timestamp or _get_now_utc()
77-
self.tools = tools or ToolRepository() # type:ignore[assignment]
77+
self.tools = tools or ToolsRepository() # type:ignore[assignment]
7878
self.authors = authors or [] # type:ignore[assignment]
7979
self.component = component
8080
self.supplier = supplier
@@ -120,21 +120,21 @@ def timestamp(self, timestamp: datetime) -> None:
120120
# ... # TODO since CDX1.5
121121

122122
@property
123-
@serializable.type_mapping(ToolRepositoryHelper)
123+
@serializable.type_mapping(ToolsRepositoryHelper)
124124
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'tool')
125125
@serializable.xml_sequence(3)
126-
def tools(self) -> ToolRepository:
126+
def tools(self) -> ToolsRepository:
127127
"""
128128
Tools used to create this BOM.
129129
130130
Returns:
131-
`ToolRepository` objects.
131+
`ToolsRepository` objects.
132132
"""
133133
return self._tools
134134

135135
@tools.setter
136-
def tools(self, tools: Union[Iterable[Tool], ToolRepository]) -> None:
137-
if isinstance(tools, ToolRepository):
136+
def tools(self, tools: Union[Iterable[Tool], ToolsRepository]) -> None:
137+
if isinstance(tools, ToolsRepository):
138138
self._tools = tools
139139
else:
140140
# This allows the old behavior of assigning the list of tools directly to bom.metadata.tools
@@ -148,7 +148,7 @@ def tools(self, tools: Union[Iterable[Tool], ToolRepository]) -> None:
148148
'Cannot serialize both old (CycloneDX <= 1.4) and new '
149149
'(CycloneDX >= 1.5) format for tools.'
150150
)
151-
self._tools = ToolRepository(tools=tools)
151+
self._tools = ToolsRepository(tools=tools)
152152

153153
@property
154154
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'author')

cyclonedx/model/tool.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from json import loads as json_loads
22
from typing import Any, Dict, Iterable, Iterator, List, Optional, Type, Union
3+
from warnings import warn
34
from xml.etree.ElementTree import Element # nosec B405
45

56
import serializable
@@ -141,7 +142,7 @@ def __repr__(self) -> str:
141142
return f'<Tool name={self.name}, version={self.version}, vendor={self.vendor}>'
142143

143144

144-
class ToolRepository:
145+
class ToolsRepository:
145146
"""
146147
The repository of tool formats
147148
@@ -151,8 +152,18 @@ class ToolRepository:
151152
and `services` attributes (which are SortedSets of their respective types).
152153
"""
153154

155+
tools: SortedSet[Tool]
156+
"""DEPRECATED tools"""
157+
158+
components: SortedSet[Component]
159+
"""An array of components used to creatd this SBOM"""
160+
161+
services: SortedSet[Service]
162+
"""An array of services used to create this SBOM"""
163+
154164
def __init__(self, *, components: Optional[Iterable[Component]] = None,
155165
services: Optional[Iterable[Service]] = None,
166+
# Deprecated in v1.5
156167
tools: Optional[Iterable[Tool]] = None) -> None:
157168

158169
if tools and (components or services):
@@ -162,9 +173,13 @@ def __init__(self, *, components: Optional[Iterable[Component]] = None,
162173
'(CycloneDX >= 1.5) format for tools.'
163174
)
164175

165-
self._components = SortedSet(components) or SortedSet()
166-
self._services = SortedSet(services) or SortedSet()
167-
self._tools = SortedSet(tools) or SortedSet()
176+
if tools:
177+
warn('Using Tool is deprecated as of CycloneDX v1.5. Components and Services should be used now. '
178+
'See https://cyclonedx.org/docs/1.5/', DeprecationWarning)
179+
180+
self._components = SortedSet(components or ())
181+
self._services = SortedSet(services or ())
182+
self._tools = SortedSet(tools or ())
168183

169184
def __len__(self) -> int:
170185
return len(self._tools)
@@ -227,9 +242,9 @@ def __iter__(self) -> Iterator[Tool]:
227242
yield t
228243

229244

230-
class ToolRepositoryHelper(BaseHelper):
245+
class ToolsRepositoryHelper(BaseHelper):
231246
@classmethod
232-
def json_normalize(cls, o: ToolRepository, *,
247+
def json_normalize(cls, o: ToolsRepository, *,
233248
view: Optional[Type[ViewType]],
234249
**__: Any) -> Any:
235250
if not any([o._tools, o.components, o.services]): # pylint: disable=protected-access
@@ -250,7 +265,7 @@ def json_normalize(cls, o: ToolRepository, *,
250265

251266
@classmethod
252267
def json_denormalize(cls, o: Union[List[Dict[str, Any]], Dict[str, Any]],
253-
**__: Any) -> ToolRepository:
268+
**__: Any) -> ToolsRepository:
254269

255270
components = []
256271
services = []
@@ -271,10 +286,10 @@ def json_denormalize(cls, o: Union[List[Dict[str, Any]], Dict[str, Any]],
271286
else:
272287
raise CycloneDxDeserializationException('unexpected: {o!r}')
273288

274-
return ToolRepository(components=components, services=services, tools=tools)
289+
return ToolsRepository(components=components, services=services, tools=tools)
275290

276291
@classmethod
277-
def xml_normalize(cls, o: ToolRepository, *,
292+
def xml_normalize(cls, o: ToolsRepository, *,
278293
element_name: str,
279294
view: Optional[Type[ViewType]],
280295
xmlns: Optional[str],
@@ -314,5 +329,5 @@ def xml_normalize(cls, o: ToolRepository, *,
314329
@classmethod
315330
def xml_denormalize(cls, o: Element,
316331
default_ns: Optional[str],
317-
**__: Any) -> ToolRepository:
318-
return ToolRepository()
332+
**__: Any) -> ToolsRepository:
333+
return ToolsRepository()

0 commit comments

Comments
 (0)