cyclonedx.contrib.bom.utils
===========================

.. py:module:: cyclonedx.contrib.bom.utils

.. autoapi-nested-parse::

   Bom related utilities



Classes
-------

.. autoapisummary::

   cyclonedx.contrib.bom.utils.BomRefDiscriminator
   cyclonedx.contrib.bom.utils.BomDependencyGraphFlatMerger


Module Contents
---------------

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

   Ensure that a collection of BomRef objects
   has unique, non‑empty :attr:`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 :meth:`reset()`
   or by using this class as a context manager.


   .. py:method:: 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.



   .. py:method:: reset() -> None

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



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


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

      This includes BomRefs from
        * :attr:`cyclonedx.model.bom.Bom.components`
        * :attr:`cyclonedx.model.bom.Bom.services`
        * :attr:`cyclonedx.model.bom.Bom.vulnerabilities`



.. py:class:: BomDependencyGraphFlatMerger(bom: cyclonedx.model.bom.Bom)

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

   When used as a context manager, the :class:`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.


   .. py:method:: flatten_merge() -> None

      Flatten and merge all :attr:`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.



   .. py:method:: reset() -> None

      Restore the :class:`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.



