Skip to content

Commit 5eb3397

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/dependencygraph-flatten-in-json
2 parents 4663019 + 9beaf5c commit 5eb3397

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
@@ -33,16 +33,19 @@
3333

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

4446
def __init__(self, bomrefs: Iterable['BomRef'], prefix: str = 'BomRef') -> None:
45-
# do not use dict/set here, different BomRefs with same value have same hash and would shadow each other
47+
# NOTE: do not use dict/set here, different BomRefs with same value
48+
# have same hash and would shadow each other.
4649
self._bomrefs = tuple((bomref, bomref.value) for bomref in bomrefs)
4750
self._prefix = prefix
4851

@@ -54,10 +57,11 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
5457

5558
def discriminate(self) -> None:
5659
"""
57-
Enforce uniqueness across all BomRef values.
60+
Enforce uniqueness across all
61+
:attr:`cyclonedx.model.bom_ref.BomRef.value`s.
5862
59-
Any BomRef whose value is `None` or duplicates a previously encountered
60-
value is assigned a newly generated unique identifier.
63+
Any BomRef whose ``value`` is ``None`` or duplicates a previously
64+
encountered value is assigned a newly generated unique identifier.
6165
"""
6266
known_values = []
6367
for bomref, _ in self._bomrefs:
@@ -69,7 +73,8 @@ def discriminate(self) -> None:
6973

7074
def reset(self) -> None:
7175
"""
72-
Restore all BomRef values to their original state.
76+
Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value`s to
77+
their original state.
7378
"""
7479
for bomref, original_value in self._bomrefs:
7580
bomref.value = original_value
@@ -80,12 +85,13 @@ def _make_unique(self) -> str:
8085
@classmethod
8186
def from_bom(cls, bom: 'Bom', prefix: str = 'BomRef') -> 'BomRefDiscriminator':
8287
"""
83-
Create a discriminator for all BomRefs contained within a BOM.
88+
Create a discriminator for all :class:`cyclonedx.model.bom_ref.BomRefs`
89+
contained within a Bom.
8490
8591
This includes BomRefs from
86-
- components
87-
- services
88-
- vulnerabilities
92+
* :attr:`cyclonedx.model.bom.Bom.components`
93+
* :attr:`cyclonedx.model.bom.Bom.services`
94+
* :attr:`cyclonedx.model.bom.Bom.vulnerabilities`
8995
"""
9096
return cls(chain(
9197
map(lambda c: c.bom_ref, bom._get_all_components()),

0 commit comments

Comments
 (0)