Skip to content

Commit d453450

Browse files
committed
chore(docs): remove issue 919 implementation notes
1 parent bf596c0 commit d453450

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

cyclonedx/model/component.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sys
2020
from collections.abc import Iterable
2121
from enum import Enum
22-
from typing import Any, Optional, Union
22+
from typing import Any, Optional, Protocol, Union
2323
from warnings import warn
2424

2525
if sys.version_info >= (3, 13):
@@ -33,7 +33,7 @@
3333
from sortedcontainers import SortedSet
3434

3535
from .._internal.bom_ref import bom_ref_from_str as _bom_ref_from_str
36-
from .._internal.compare import ComparablePackageURL as _ComparablePackageURL, ComparableTuple as _ComparableTuple
36+
from .._internal.compare import ComparableTuple as _ComparableTuple
3737
from ..exception.model import InvalidOmniBorIdException, InvalidSwhidException
3838
from ..exception.serialization import (
3939
CycloneDxDeserializationException,
@@ -50,7 +50,6 @@
5050
SchemaVersion1Dot6,
5151
SchemaVersion1Dot7,
5252
)
53-
from ..serialization import PackageUrl as PackageUrlSH
5453
from . import (
5554
AttachedText,
5655
ExternalReference,
@@ -949,6 +948,13 @@ def __str__(self) -> str:
949948
return self._id
950949

951950

951+
952+
953+
class _StringCastable(Protocol):
954+
955+
def __str__(self) -> str: ...
956+
957+
952958
@serializable.serializable_class(ignore_unknown_during_deserialization=True)
953959
class Component(Dependable):
954960
"""
@@ -995,7 +1001,7 @@ def __init__(
9951001
hashes: Optional[Iterable[HashType]] = None,
9961002
licenses: Optional[Iterable[License]] = None,
9971003
copyright: Optional[str] = None,
998-
purl: Optional[PackageURL] = None,
1004+
purl: Optional[_StringCastable] = None,
9991005
external_references: Optional[Iterable[ExternalReference]] = None,
10001006
properties: Optional[Iterable[Property]] = None,
10011007
release_notes: Optional[ReleaseNotes] = None,
@@ -1377,23 +1383,23 @@ def cpe(self, cpe: Optional[str]) -> None:
13771383
self._cpe = cpe
13781384

13791385
@property
1380-
@serializable.type_mapping(PackageUrlSH)
13811386
@serializable.xml_sequence(15)
1382-
def purl(self) -> Optional[PackageURL]:
1387+
@serializable.xml_string(serializable.XmlStringSerializationType.NORMALIZED_STRING)
1388+
def purl(self) -> Optional[str]:
13831389
"""
13841390
Specifies the package-url (PURL).
13851391
13861392
The purl, if specified, must be valid and conform to the specification defined at:
13871393
https://github.com/package-url/purl-spec
13881394
13891395
Returns:
1390-
`PackageURL` or `None`
1396+
`str` or `None`
13911397
"""
13921398
return self._purl
13931399

13941400
@purl.setter
1395-
def purl(self, purl: Optional[PackageURL]) -> None:
1396-
self._purl = purl
1401+
def purl(self, purl: Optional[_StringCastable]) -> None:
1402+
self._purl = None if purl is None else str(purl)
13971403

13981404
@property
13991405
@serializable.json_name('omniborId')
@@ -1680,7 +1686,7 @@ def __comparable_tuple(self) -> _ComparableTuple:
16801686
return _ComparableTuple((
16811687
self.type, self.group, self.name, self.version,
16821688
self.bom_ref.value,
1683-
None if self.purl is None else _ComparablePackageURL(self.purl),
1689+
self.purl,
16841690
self.swid, self.cpe, _ComparableTuple(self.swhids),
16851691
self.supplier, self.author, self.publisher,
16861692
self.description,

tests/_data/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def get_bom_with_component_setuptools_with_vulnerability() -> Bom:
550550
),
551551
affects=[
552552
BomTarget(
553-
ref=component.purl.to_string(),
553+
ref=str(component.purl),
554554
versions=[BomTargetVersionRange(
555555
range='49.0.0 - 54.0.0', status=ImpactAnalysisAffectedStatus.AFFECTED
556556
)]

tests/test_component.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ class TestComponent(TestCase):
3131

3232
def test_purl_correct(self) -> None:
3333
self.assertEqual(
34-
PackageURL(
35-
type='pypi', name='setuptools', version='50.3.2', qualifiers='extension=tar.gz'
36-
),
34+
'pkg:pypi/setuptools@50.3.2?extension=tar.gz',
3735
get_component_setuptools_simple().purl
3836
)
3937

@@ -72,5 +70,12 @@ def test_from_xml_file_with_path_for_bom(self) -> None:
7270
purl = PackageURL(
7371
type='generic', name='fixtures/bom_setuptools.xml', version=expected_version
7472
)
75-
self.assertEqual(c.purl, purl)
73+
self.assertEqual(c.purl, str(purl))
7674
self.assertEqual(len(c.hashes), 1)
75+
76+
77+
def test_purl_casted_to_string(self) -> None:
78+
purl = PackageURL(type='pypi', name='example', version='1.2.3')
79+
component = Component(name='example', purl=purl)
80+
81+
self.assertEqual(component.purl, str(purl))

0 commit comments

Comments
 (0)