2424import pathlib
2525from typing import List
2626
27+ import jsonschema
2728from hoppr_cyclonedx_models .cyclonedx_1_4 import Component
2829from hoppr_cyclonedx_models .cyclonedx_1_4 import (
2930 CyclonedxSoftwareBillOfMaterialsStandard as Bom_1_4 ,
4243
4344
4445def get_bom (cyclonedx_document : dict ):
46+ """
47+ Return CycloneDx BOM object
48+ """
4549 return Bom_1_4 (** cyclonedx_document )
4650
4751
@@ -50,6 +54,9 @@ def get_components(bom: Bom_1_4):
5054
5155
5256def bom_iterable_to_dict (iterable ):
57+ """
58+ Return list dict from a list of CycloneDx item obj
59+ """
5360 return [
5461 json .loads (obj .json (exclude_unset = True , by_alias = True ))
5562 for obj in iterable or []
@@ -59,6 +66,9 @@ def bom_iterable_to_dict(iterable):
5966def recursive_component_collector (
6067 root_component_list : List [Component ], collected : List = []
6168):
69+ """
70+ Return list of components including the nested components
71+ """
6272 for component in root_component_list or []:
6373 extra_data = (
6474 bom_iterable_to_dict (component .components )
@@ -71,6 +81,9 @@ def recursive_component_collector(
7181
7282
7383def resolve_license (item ):
84+ """
85+ Return license expression/id/name from license item
86+ """
7487 return (
7588 item ["expression" ]
7689 if "expression" in item
@@ -83,6 +96,9 @@ def resolve_license(item):
8396
8497
8598def get_declared_licenses (list_of_license_obj ):
99+ """
100+ Return resolved license from list of LicenseChoice obj
101+ """
86102 return "\n " .join (
87103 [
88104 resolve_license (item )
@@ -92,6 +108,9 @@ def get_declared_licenses(list_of_license_obj):
92108
93109
94110def get_checksums (component : Component ):
111+ """
112+ Return dict of all the checksums from a component
113+ """
95114 algorithm_map_cdx_scio = {
96115 "MD5" : "md5" ,
97116 "SHA-1" : "sha1" ,
@@ -106,6 +125,9 @@ def get_checksums(component: Component):
106125
107126
108127def get_external_refrences (external_references ):
128+ """
129+ Return dict of refrence urls from list of `externalRefrences` obj
130+ """
109131 refrences = {
110132 "vcs" : [],
111133 "issue-tracker" : [],
@@ -135,15 +157,6 @@ def validate_document(document, schema=CYCLONEDX_JSON_SCHEMA_PATH):
135157 CYCLONEDX document validation.
136158 Requires the `jsonschema` library.
137159 """
138- try :
139- import jsonschema
140- except ModuleNotFoundError :
141- print (
142- "The `jsonschema` library is required to run the validation.\n "
143- "Install with: `pip install jsonschema`"
144- )
145- raise
146-
147160 if isinstance (document , str ):
148161 document = json .loads (document )
149162
0 commit comments