Display the detected SPDX identifiers and their validity in Fedora

This commit is contained in:
Karolina Surma
2024-10-10 09:49:42 +02:00
parent 3163be3ab8
commit e828452064
3 changed files with 33 additions and 19 deletions
+18 -11
View File
@@ -149,10 +149,11 @@ def _is_compliant_with_fedora(identifier, fedora_licenses):
def good_for_fedora(spdx_identifiers, *, licenses_dict=None, session=None):
"""Determine whether all of the given SPDX identifiers are good for Fedora.
If no `spdx_identifiers` are given, return tuple: (False, []).
If all of the given identifiers are good, return (True, []),
otherwise return (False, [<all bad identifiers>]).
bad_identifiers are returned in the same order as the given spdx_identifiers.
Store the results in the checked_identifiers dictionary, under the
respective `bad` and `good` keys.
If no `spdx_identifiers` are given or not all are good, return tuple:
(False, checked_identifies).
Otherwise, return (True, checked_identifies).
"""
# populate FEDORA_LICENSES only if they're still empty and
@@ -161,12 +162,18 @@ def good_for_fedora(spdx_identifiers, *, licenses_dict=None, session=None):
FEDORA_LICENSES.update(_load_fedora_licenses(session=session))
fedora_licenses = licenses_dict or FEDORA_LICENSES
checked_identifies = {
"bad": [],
"good": [],
}
if not spdx_identifiers:
return (False, [])
bad_identifiers = []
return (False, checked_identifies)
for spdx_identifier in spdx_identifiers:
if not _is_compliant_with_fedora(spdx_identifier, fedora_licenses):
bad_identifiers.append(spdx_identifier)
if bad_identifiers:
return (False, bad_identifiers)
return (True, [])
if _is_compliant_with_fedora(spdx_identifier, fedora_licenses):
checked_identifies["good"].append(spdx_identifier)
else:
checked_identifies["bad"].append(spdx_identifier)
if checked_identifies["bad"]:
return (False, checked_identifies)
return (True, checked_identifies)
+11 -4
View File
@@ -202,11 +202,18 @@ class PypiPackage:
click.secho(err_string, fg="red")
return None
if check_compliance:
is_compliant, bad_identifiers = good_for_fedora(identifiers, session=self._session, licenses_dict=licenses_dict)
is_compliant, checked_identifiers = good_for_fedora(
identifiers,
session=self._session,
licenses_dict=licenses_dict
)
if checked_identifiers["bad"]:
err_string = "Found identifiers: `{0}` aren't allowed in Fedora."
click.secho(err_string.format(", ".join(checked_identifiers["bad"])), fg="red")
if checked_identifiers["good"]:
err_string = "Found identifiers: `{0}` are good for Fedora."
click.secho(err_string.format(", ".join(checked_identifiers["good"])), fg="green")
if not is_compliant:
if bad_identifiers:
err_string = "The detected licenses: `{0}` aren't allowed in Fedora."
click.secho(err_string.format(", ".join(bad_identifiers), fg="red"))
return None
return expression
+4 -4
View File
@@ -85,10 +85,10 @@ def test_compliance_check_with_fedora(identifier, expected, fake_fedora_licenses
@pytest.mark.parametrize(
("identifiers", "expected"),
(
(["AAL", "MIT", "CECILL-B"], (True, [])),
([], (False, [])),
(["LicenseRef-LPPL", "MIT"], (False, ["LicenseRef-LPPL"])), # mixed not allowed/allowed
(["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"], (False, ["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"])),
(["AAL", "MIT", "CECILL-B"], (True, {"bad": [], "good": ["AAL", "MIT", "CECILL-B"]})),
([], (False, {"bad": [], "good": []})),
(["LicenseRef-LPPL", "MIT"], (False, {"bad": ["LicenseRef-LPPL"], "good": ["MIT"]})), # mixed not allowed/allowed
(["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"], (False, {"bad": ["LicenseRef-LPPL", "Aladdin", "LicenseRef-OpenFlow", "APL-1.0"], "good": []})),
),
)
def test_is_allowed_in_fedora(identifiers, expected, fake_fedora_licenses):