Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sp_repo_review/families.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Family(typing.TypedDict, total=False):

def get_families(pyproject: dict[str, Any]) -> dict[str, Family]:
pyproject_description = f"- Detected build backend: `{pyproject.get('build-system', {}).get('build-backend', 'MISSING')}`"
if classifiers := pyproject.get("project", {}).get("classifiers", []):
if isinstance(license := pyproject.get("project", {}).get("license", {}), str):
pyproject_description += f"\n- SPDX license expression: `{license}`"
elif classifiers := pyproject.get("project", {}).get("classifiers", []):
licenses = [
c.removeprefix("License :: ").removeprefix("OSI Approved :: ")
for c in classifiers
Expand Down
47 changes: 47 additions & 0 deletions tests/test_families.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from sp_repo_review.families import get_families


def test_backend():
pyproject = {
"build-system": {
"requires": ["setuptools"],
"build-backend": "setuptools.build_meta",
},
}
families = get_families(pyproject)
assert families["general"].get("description") == (
"- Detected build backend: `setuptools.build_meta`"
)


def test_spdx_license():
pyproject = {
"project": {
"license": "MIT",
"classifiers": [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: BSD License",
],
},
}
families = get_families(pyproject)
assert families["general"].get("description") == (
"- Detected build backend: `MISSING`\n- SPDX license expression: `MIT`"
)


def test_classic_license():
pyproject = {
"project": {
"license": {"text": "Free-form"},
"classifiers": [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: BSD License",
],
},
}
families = get_families(pyproject)
assert families["general"].get("description") == (
"- Detected build backend: `MISSING`\n"
"- Detected license(s): MIT License, BSD License"
)