Skip to content

Commit 9beaf5c

Browse files
authored
docs: improve docs of contrib.bom.utils.BomRefDiscriminator (#996)
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 3bb87aa commit 9beaf5c

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

cyclonedx/contrib/bom/utils.py

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

3232
class BomRefDiscriminator:
3333
"""
34-
Ensure that a collection of 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. Original values are preserved so they can be
39-
restored later via `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:
43-
# do not use dict/set here, different BomRefs with same value have same hash and would shadow each other
45+
# NOTE: do not use dict/set here, different BomRefs with same value
46+
# have same hash and would shadow each other.
4447
self._bomrefs = tuple((bomref, bomref.value) for bomref in bomrefs)
4548
self._prefix = prefix
4649

@@ -52,10 +55,11 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
5255

5356
def discriminate(self) -> None:
5457
"""
55-
Enforce uniqueness across all BomRef values.
58+
Enforce uniqueness across all
59+
:attr:`cyclonedx.model.bom_ref.BomRef.value`s.
5660
57-
Any BomRef whose value is `None` or duplicates a previously encountered
58-
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.
5963
"""
6064
known_values = []
6165
for bomref, _ in self._bomrefs:
@@ -67,7 +71,8 @@ def discriminate(self) -> None:
6771

6872
def reset(self) -> None:
6973
"""
70-
Restore all BomRef values to their original state.
74+
Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value`s to
75+
their original state.
7176
"""
7277
for bomref, original_value in self._bomrefs:
7378
bomref.value = original_value
@@ -78,12 +83,13 @@ def _make_unique(self) -> str:
7883
@classmethod
7984
def from_bom(cls, bom: 'Bom', prefix: str = 'BomRef') -> 'BomRefDiscriminator':
8085
"""
81-
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.
8288
8389
This includes BomRefs from
84-
- components
85-
- services
86-
- vulnerabilities
90+
* :attr:`cyclonedx.model.bom.Bom.components`
91+
* :attr:`cyclonedx.model.bom.Bom.services`
92+
* :attr:`cyclonedx.model.bom.Bom.vulnerabilities`
8793
"""
8894
return cls(chain(
8995
map(lambda c: c.bom_ref, bom._get_all_components()),

0 commit comments

Comments
 (0)