cyclonedx.contrib.bom.utils

Bom related utilities

Classes

BomRefDiscriminator

Ensure that a collection of BomRef objects

BomDependencyGraphFlatMerger

Context‑manager utility that temporarily flattens and merges all

Module Contents

class cyclonedx.contrib.bom.utils.BomRefDiscriminator(bomrefs: collections.abc.Iterable[cyclonedx.model.bom_ref.BomRef], prefix: str = 'BomRef')

Ensure that a collection of BomRef objects has unique, non‑empty cyclonedx.model.bom_ref.BomRef.value.

The discriminator inspects each provided BomRef and assigns a newly generated identifier to any instance whose value is missing or duplicates an earlier one. All original values are preserved and can be restored via reset() or by using this class as a context manager.

discriminate() None

Enforce uniqueness across all :attr:`cyclonedx.model.bom_ref.BomRef.value`s.

Any BomRef whose value is None or duplicates a previously encountered value is assigned a newly generated unique identifier.

reset() None

Restore all :attr:`cyclonedx.model.bom_ref.BomRef.value`s to their original state.

classmethod from_bom(bom: cyclonedx.model.bom.Bom, prefix: str = 'BomRef') BomRefDiscriminator

Create a discriminator for all cyclonedx.model.bom_ref.BomRefs contained within a Bom.

This includes BomRefs from
class cyclonedx.contrib.bom.utils.BomDependencyGraphFlatMerger(bom: cyclonedx.model.bom.Bom)

Context‑manager utility that temporarily flattens and merges all cyclonedx.model.bom.Bom.dependencies.

When used as a context manager, the cyclonedx.model.bom.Bom’s dependency graph is replaced with a flattened, merged representation for the duration of the with block and automatically restored afterward.

flatten_merge() None

Flatten and merge all cyclonedx.model.bom.Bom.dependencies.

This produces a non‑recursive, merged representation of the entire dependency graph and assigns it to the Bom.

Note

The original dependency graph is not modified. A new, flattened dependency structure is assigned to the Bom.

reset() None

Restore the cyclonedx.model.bom.Bom’s dependency graph to its original state.

Note

This does not modify the dependency graph. It simply reassigns the original dependency collection back to the Bom.