Skip to content

Commit 6dd7239

Browse files
authored
fix: detect SPDX licenses too (#591)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent babf682 commit 6dd7239

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/sp_repo_review/families.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class Family(typing.TypedDict, total=False):
1818

1919
def get_families(pyproject: dict[str, Any]) -> dict[str, Family]:
2020
pyproject_description = f"- Detected build backend: `{pyproject.get('build-system', {}).get('build-backend', 'MISSING')}`"
21-
if classifiers := pyproject.get("project", {}).get("classifiers", []):
21+
if isinstance(license := pyproject.get("project", {}).get("license", {}), str):
22+
pyproject_description += f"\n- SPDX license expression: `{license}`"
23+
elif classifiers := pyproject.get("project", {}).get("classifiers", []):
2224
licenses = [
2325
c.removeprefix("License :: ").removeprefix("OSI Approved :: ")
2426
for c in classifiers

tests/test_families.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from sp_repo_review.families import get_families
2+
3+
4+
def test_backend():
5+
pyproject = {
6+
"build-system": {
7+
"requires": ["setuptools"],
8+
"build-backend": "setuptools.build_meta",
9+
},
10+
}
11+
families = get_families(pyproject)
12+
assert families["general"].get("description") == (
13+
"- Detected build backend: `setuptools.build_meta`"
14+
)
15+
16+
17+
def test_spdx_license():
18+
pyproject = {
19+
"project": {
20+
"license": "MIT",
21+
"classifiers": [
22+
"License :: OSI Approved :: MIT License",
23+
"License :: OSI Approved :: BSD License",
24+
],
25+
},
26+
}
27+
families = get_families(pyproject)
28+
assert families["general"].get("description") == (
29+
"- Detected build backend: `MISSING`\n- SPDX license expression: `MIT`"
30+
)
31+
32+
33+
def test_classic_license():
34+
pyproject = {
35+
"project": {
36+
"license": {"text": "Free-form"},
37+
"classifiers": [
38+
"License :: OSI Approved :: MIT License",
39+
"License :: OSI Approved :: BSD License",
40+
],
41+
},
42+
}
43+
families = get_families(pyproject)
44+
assert families["general"].get("description") == (
45+
"- Detected build backend: `MISSING`\n"
46+
"- Detected license(s): MIT License, BSD License"
47+
)

0 commit comments

Comments
 (0)