Skip to content

fix: issue DeprecationWarnings for deprecated properties properly #838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ def __init__(
self.properties = properties or []
self.manufacturer = manufacturer
self.lifecycles = lifecycles or []

# deprecated properties below
self.manufacture = manufacture
if manufacture:
warn(
'`bom.metadata.manufacture` is deprecated from CycloneDX v1.6 onwards. '
'Please use `bom.metadata.component.manufacturer` instead.',
DeprecationWarning)

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

@property
Expand Down
22 changes: 11 additions & 11 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,11 +1010,9 @@ def __init__(
self.supplier = supplier
self.manufacturer = manufacturer
self.authors = authors or []
self.author = author
self.publisher = publisher
self.group = group
self.name = name
self.version = version
self.description = description
self.scope = scope
self.hashes = hashes or []
Expand All @@ -1025,7 +1023,6 @@ def __init__(
self.omnibor_ids = omnibor_ids or []
self.swhids = swhids or []
self.swid = swid
self.modified = modified
self.pedigree = pedigree
self.external_references = external_references or []
self.properties = properties or []
Expand All @@ -1034,13 +1031,10 @@ def __init__(
self.release_notes = release_notes
self.crypto_properties = crypto_properties
self.tags = tags or []

if modified:
warn('`.component.modified` is deprecated from CycloneDX v1.3 onwards. '
'Please use `@.pedigree` instead.', DeprecationWarning)
if author:
warn('`.component.author` is deprecated from CycloneDX v1.6 onwards. '
'Please use `@.authors` or `@.manufacturer` instead.', DeprecationWarning)
# spec-deprecated properties below
self.author = author
self.modified = modified
self.version = version

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

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

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

@property
Expand Down Expand Up @@ -1450,6 +1447,9 @@ def modified(self) -> bool:

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

@property
Expand Down
9 changes: 5 additions & 4 deletions cyclonedx/model/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,9 @@ def __init__(
# Deprecated since v1.5
tools: Optional[Iterable[Tool]] = None
) -> None:
if tools:
warn('`@.tools` is deprecated from CycloneDX v1.5 onwards. '
'Please use `@.components` and `@.services` instead.',
DeprecationWarning)
self.components = components or ()
self.services = services or ()
# spec-deprecated properties below
self.tools = tools or ()

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

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

def __len__(self) -> int:
Expand Down