Skip to content

Commit

Permalink
Display the detected SPDX identifiers and their validity in Fedora
Browse files Browse the repository at this point in the history
  • Loading branch information
befeleme committed Oct 1, 2024
1 parent 54bdc49 commit 0d4307c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
29 changes: 18 additions & 11 deletions pyp2spec/license_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, return tuple: (False, checked_identifies).
If all of the given identifiers are good, return (True, checked_identifies),
otherwise return (False, checked_identifies).
"""

# populate FEDORA_LICENSES only if they're still empty and
Expand All @@ -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)
15 changes: 11 additions & 4 deletions pyp2spec/pyp2conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,18 @@ def license(self, *, check_compliance=False, licenses_dict=None):
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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_license_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0d4307c

Please sign in to comment.