|
30 | 30 |
|
31 | 31 | import sys |
32 | 32 |
|
| 33 | +from cyclonedx.exception.model import CycloneDxModelException |
| 34 | + |
33 | 35 | # See https://github.com/package-url/packageurl-python/issues/65 |
34 | 36 | from packageurl import PackageURL # type: ignore |
35 | 37 | from pkg_resources import DistInfoDistribution # type: ignore |
@@ -70,22 +72,30 @@ def __init__(self, use_purl_bom_ref: bool = False) -> None: |
70 | 72 | if 'Author' in i_metadata: |
71 | 73 | c.author = i_metadata['Author'] |
72 | 74 |
|
73 | | - if 'License' in i_metadata and i_metadata['License'] != 'UNKNOWN': |
| 75 | + if 'License' in i_metadata and i_metadata['License'] and i_metadata['License'] != 'UNKNOWN': |
74 | 76 | # Values might be ala `MIT` (SPDX id), `Apache-2.0 license` (arbitrary string), ... |
75 | 77 | # Therefore, just go with a named license. |
76 | | - c.licenses.add(LicenseChoice(license_=License(license_name=i_metadata['License']))) |
| 78 | + try: |
| 79 | + c.licenses.add(LicenseChoice(license_=License(license_name=i_metadata['License']))) |
| 80 | + except CycloneDxModelException: |
| 81 | + # write a debug message? |
| 82 | + pass |
77 | 83 |
|
78 | 84 | for classifier in i_metadata.get_all("Classifier", []): |
79 | 85 | # Trove classifiers - https://packaging.python.org/specifications/core-metadata/#metadata-classifier |
80 | 86 | # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers |
81 | 87 | if str(classifier).startswith('License :: OSI Approved :: '): |
82 | | - c.licenses.add(LicenseChoice(license_=License( |
83 | | - license_name=str(classifier).replace('License :: OSI Approved :: ', '').strip() |
84 | | - ))) |
| 88 | + license_name = str(classifier).replace('License :: OSI Approved :: ', '').strip() |
85 | 89 | elif str(classifier).startswith('License :: '): |
86 | | - c.licenses.add(LicenseChoice(license_=License( |
87 | | - license_name=str(classifier).replace('License :: ', '').strip() |
88 | | - ))) |
| 90 | + license_name = str(classifier).replace('License :: ', '').strip() |
| 91 | + else: |
| 92 | + license_name = '' |
| 93 | + if license_name: |
| 94 | + try: |
| 95 | + c.licenses.add(LicenseChoice(license_=License(license_name=license_name))) |
| 96 | + except CycloneDxModelException: |
| 97 | + # write a debug message? |
| 98 | + pass |
89 | 99 |
|
90 | 100 | self._components.append(c) |
91 | 101 |
|
|
0 commit comments