Skip to content

Commit 32d6dd8

Browse files
committed
docs: improve docs of contrib.bom.utils.BomRefDiscriminator
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 9a450f9 commit 32d6dd8

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

cyclonedx/contrib/bom/utils.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131

3232
class BomRefDiscriminator:
3333
"""
34-
Ensure that a collection of :class:`cyclonedx.model.bom_ref.BomRef` objects has unique, non‑empty values.
35-
36-
The discriminator inspects the provided BomRef instances and assigns new,
37-
automatically generated identifiers to any BomRef whose value is missing
38-
or duplicates another.
39-
Original values are preserved so they can be restored later via :meth:`reset()` or by using this class as a context manager.
34+
Ensure that a collection of BomRef objects
35+
has unique, non‑empty :attr:`cyclonedx.model.bom_ref.BomRef.value`.
36+
37+
The discriminator inspects each provided BomRef and assigns a newly
38+
generated identifier to any instance whose ``value`` is missing or
39+
duplicates an earlier one.
40+
All original values are preserved and can be restored via :meth:`reset()`
41+
or by using this class as a context manager.
4042
"""
4143

4244
def __init__(self, bomrefs: Iterable['BomRef'], prefix: str = 'BomRef') -> None:
@@ -53,11 +55,11 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
5355

5456
def discriminate(self) -> None:
5557
"""
56-
Enforce uniqueness across all :attr:`cyclonedx.model.bom_ref.BomRef.value`.
58+
Enforce uniqueness across all
59+
:attr:`cyclonedx.model.bom_ref.BomRef.value`s.
5760
58-
.. note::
59-
Any BomRef whose value is ``None`` or duplicates a previously encountered
60-
value is assigned a newly generated unique identifier.
61+
Any BomRef whose ``value`` is ``None`` or duplicates a previously
62+
encountered value is assigned a newly generated unique identifier.
6163
"""
6264
known_values = []
6365
for bomref, _ in self._bomrefs:
@@ -69,7 +71,8 @@ def discriminate(self) -> None:
6971

7072
def reset(self) -> None:
7173
"""
72-
Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value` to their original state.
74+
Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value`s to
75+
their original state.
7376
"""
7477
for bomref, original_value in self._bomrefs:
7578
bomref.value = original_value
@@ -80,12 +83,13 @@ def _make_unique(self) -> str:
8083
@classmethod
8184
def from_bom(cls, bom: 'Bom', prefix: str = 'BomRef') -> 'BomRefDiscriminator':
8285
"""
83-
Create a discriminator for all BomRefs contained within a BOM.
86+
Create a discriminator for all :class:`cyclonedx.model.bom_ref.BomRefs`
87+
contained within a Bom.
8488
8589
This includes BomRefs from
86-
* components
87-
* services
88-
* vulnerabilities
90+
* :attr:`cyclonedx.model.bom.Bom.components`
91+
* :attr:`cyclonedx.model.bom.Bom.services`
92+
* :attr:`cyclonedx.model.bom.Bom.vulnerabilities`
8993
"""
9094
return cls(chain(
9195
map(lambda c: c.bom_ref, bom._get_all_components()),

0 commit comments

Comments
 (0)