Skip to content

Commit d5eb743

Browse files
committed
removed implementation of PEP639, removed raise, and updated test file
Signed-off-by: Manav Gupta <[email protected]>
1 parent e048980 commit d5eb743

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

cyclonedx_py/_internal/utils/pep621.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def project2licenses(project: dict[str, Any], lfac: 'LicenseFactory', *,
6161
# https://packaging.python.org/en/latest/specifications/core-metadata/#classifier-multiple-use
6262
yield from classifiers2licenses(classifiers, lfac, lack)
6363
if plicense := project.get('license'):
64-
# Handle both PEP 621 (dict) and PEP 639 (str) license formats
64+
# Only handle PEP 621 (dict) license formats
6565
if isinstance(plicense, dict):
6666
if 'file' in plicense and 'text' in plicense:
6767
raise ValueError('`license.file` and `license.text` are mutually exclusive,')
@@ -80,12 +80,7 @@ def project2licenses(project: dict[str, Any], lfac: 'LicenseFactory', *,
8080
text=AttachedText(content=plicense_text))
8181
else:
8282
yield license
83-
elif isinstance(plicense, str):
84-
# PEP 639: license is a string (SPDX expression or license reference)
85-
license = lfac.make_from_string(plicense, license_acknowledgement=lack)
86-
yield license
87-
else:
88-
raise TypeError(f"Unexpected type for 'license': {type(plicense)}")
83+
# Silently skip any other types (including string/PEP 639)
8984

9085

9186
def project2extrefs(project: dict[str, Any]) -> Generator['ExternalReference', None, None]:

tests/unit/test_pep621.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,19 @@
44

55
import os
66
import tempfile
7-
from unittest import TestCase
7+
import unittest
88

99
from cyclonedx.factory.license import LicenseFactory
1010
from cyclonedx.model.license import DisjunctiveLicense, LicenseAcknowledgement
1111

1212
from cyclonedx_py._internal.utils.pep621 import project2licenses
1313

1414

15-
class TestProject2Licenses(TestCase):
15+
class TestPEP621(unittest.TestCase):
1616
def setUp(self):
1717
self.lfac = LicenseFactory()
1818
self.fpath = tempfile.mktemp()
1919

20-
def test_license_string_pep639(self):
21-
project = {
22-
'name': 'testpkg',
23-
'license': 'LicenseRef-Platform-Software-General-1.0',
24-
}
25-
licenses = list(project2licenses(project, self.lfac, fpath=self.fpath))
26-
self.assertEqual(len(licenses), 1)
27-
lic = licenses[0]
28-
self.assertIsInstance(lic, DisjunctiveLicense)
29-
self.assertEqual(lic.acknowledgement, LicenseAcknowledgement.DECLARED)
30-
if lic.id is not None:
31-
self.assertEqual(lic.id, 'LicenseRef-Platform-Software-General-1.0')
32-
elif lic.text is not None:
33-
self.assertEqual(lic.text.content, 'LicenseRef-Platform-Software-General-1.0')
34-
else:
35-
# Acceptable fallback: both id and text are None for unknown license references
36-
self.assertIsNone(lic.id)
37-
self.assertIsNone(lic.text)
38-
3920
def test_license_dict_text_pep621(self):
4021
project = {
4122
'name': 'testpkg',

0 commit comments

Comments
 (0)