Skip to content

Commit 34a11aa

Browse files
KAWAHARA-soutaSouta Kawaharajkowalleck
authored
fix: issue DeprecationWarnings for deprecated properties properly (#838)
Resolves: #837 --------- Signed-off-by: Souta Kawahara <souta.kawahara@almalinux.org> Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com> Co-authored-by: Souta Kawahara <souta.kawahara@almalinux.org> Co-authored-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 0bdc6d6 commit 34a11aa

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

cyclonedx/model/bom.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,8 @@ def __init__(
8787
self.properties = properties or []
8888
self.manufacturer = manufacturer
8989
self.lifecycles = lifecycles or []
90-
90+
# deprecated properties below
9191
self.manufacture = manufacture
92-
if manufacture:
93-
warn(
94-
'`bom.metadata.manufacture` is deprecated from CycloneDX v1.6 onwards. '
95-
'Please use `bom.metadata.component.manufacturer` instead.',
96-
DeprecationWarning)
9792

9893
@property
9994
@serializable.type_mapping(serializable.helpers.XsdDateTime)
@@ -214,6 +209,11 @@ def manufacture(self, manufacture: Optional[OrganizationalEntity]) -> None:
214209
@todo Based on https://github.com/CycloneDX/specification/issues/346,
215210
we should set this data on `.component.manufacturer`.
216211
"""
212+
if manufacture is not None:
213+
warn(
214+
'`bom.metadata.manufacture` is deprecated from CycloneDX v1.6 onwards. '
215+
'Please use `bom.metadata.component.manufacturer` instead.',
216+
DeprecationWarning)
217217
self._manufacture = manufacture
218218

219219
@property

cyclonedx/model/component.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,11 +1010,9 @@ def __init__(
10101010
self.supplier = supplier
10111011
self.manufacturer = manufacturer
10121012
self.authors = authors or []
1013-
self.author = author
10141013
self.publisher = publisher
10151014
self.group = group
10161015
self.name = name
1017-
self.version = version
10181016
self.description = description
10191017
self.scope = scope
10201018
self.hashes = hashes or []
@@ -1025,7 +1023,6 @@ def __init__(
10251023
self.omnibor_ids = omnibor_ids or []
10261024
self.swhids = swhids or []
10271025
self.swid = swid
1028-
self.modified = modified
10291026
self.pedigree = pedigree
10301027
self.external_references = external_references or []
10311028
self.properties = properties or []
@@ -1034,13 +1031,10 @@ def __init__(
10341031
self.release_notes = release_notes
10351032
self.crypto_properties = crypto_properties
10361033
self.tags = tags or []
1037-
1038-
if modified:
1039-
warn('`.component.modified` is deprecated from CycloneDX v1.3 onwards. '
1040-
'Please use `@.pedigree` instead.', DeprecationWarning)
1041-
if author:
1042-
warn('`.component.author` is deprecated from CycloneDX v1.6 onwards. '
1043-
'Please use `@.authors` or `@.manufacturer` instead.', DeprecationWarning)
1034+
# spec-deprecated properties below
1035+
self.author = author
1036+
self.modified = modified
1037+
self.version = version
10441038

10451039
@property
10461040
@serializable.type_mapping(_ComponentTypeSerializationHelper)
@@ -1175,6 +1169,9 @@ def author(self) -> Optional[str]:
11751169

11761170
@author.setter
11771171
def author(self, author: Optional[str]) -> None:
1172+
if author is not None:
1173+
warn('`@.author` is deprecated from CycloneDX v1.6 onwards. '
1174+
'Please use `@.authors` or `@.manufacturer` instead.', DeprecationWarning)
11781175
self._author = author
11791176

11801177
@property
@@ -1255,7 +1252,7 @@ def version(self) -> Optional[str]:
12551252
@version.setter
12561253
def version(self, version: Optional[str]) -> None:
12571254
if version and len(version) > 1024:
1258-
warn('`.component.version`has a maximum length of 1024 from CycloneDX v1.6 onwards.', UserWarning)
1255+
warn('`@.version`has a maximum length of 1024 from CycloneDX v1.6 onwards.', UserWarning)
12591256
self._version = version
12601257

12611258
@property
@@ -1450,6 +1447,9 @@ def modified(self) -> bool:
14501447

14511448
@modified.setter
14521449
def modified(self, modified: bool) -> None:
1450+
if modified:
1451+
warn('`@.modified` is deprecated from CycloneDX v1.3 onwards. '
1452+
'Please use `@.pedigree` instead.', DeprecationWarning)
14531453
self._modified = modified
14541454

14551455
@property

cyclonedx/model/tool.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,9 @@ def __init__(
203203
# Deprecated since v1.5
204204
tools: Optional[Iterable[Tool]] = None
205205
) -> None:
206-
if tools:
207-
warn('`@.tools` is deprecated from CycloneDX v1.5 onwards. '
208-
'Please use `@.components` and `@.services` instead.',
209-
DeprecationWarning)
210206
self.components = components or ()
211207
self.services = services or ()
208+
# spec-deprecated properties below
212209
self.tools = tools or ()
213210

214211
@property
@@ -241,6 +238,10 @@ def tools(self) -> 'SortedSet[Tool]':
241238

242239
@tools.setter
243240
def tools(self, tools: Iterable[Tool]) -> None:
241+
if tools:
242+
warn('`@.tools` is deprecated from CycloneDX v1.5 onwards. '
243+
'Please use `@.components` and `@.services` instead.',
244+
DeprecationWarning)
244245
self._tools = SortedSet(tools)
245246

246247
def __len__(self) -> int:

0 commit comments

Comments
 (0)