Skip to content

Commit 1c90023

Browse files
committed
fix: normalize license expression
Signed-off-by: Henry Schreiner <[email protected]>
1 parent a728199 commit 1c90023

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ repos:
8282
- ninja
8383
- nox
8484
- orjson
85-
- packaging
85+
- packaging>=24.2
8686
- pytest
8787
- pytest-subprocess
8888
- rich

src/scikit_build_core/build/metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,17 @@ def get_standard_metadata(
9191
msg = "Multiple lines in project.description are not supported; this is supposed to be a one line summary"
9292
raise ValueError(msg)
9393

94+
# Validate license if possible.
95+
if isinstance(metadata.license, str):
96+
try:
97+
import packaging.licenses
98+
99+
metadata.license = packaging.licenses.canonicalize_license_expression(
100+
metadata.license
101+
)
102+
except ImportError:
103+
logger.warning(
104+
"Packaging 24.2+ required for license normalization. Please update (Python 3.8+ required)"
105+
)
106+
94107
return metadata

tests/test_prepare_metadata.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,14 @@ def test_multiline_description():
7777
},
7878
settings=ScikitBuildSettings(minimum_version=Version("0.8")),
7979
)
80+
81+
82+
def test_license_normalization():
83+
pytest.importorskip("packaging.licenses")
84+
metadata = get_standard_metadata(
85+
pyproject_dict={
86+
"project": {"name": "hello", "version": "1.1.1", "license": "ApacHE-2.0"}
87+
},
88+
settings=ScikitBuildSettings(),
89+
)
90+
assert metadata.license == "Apache-2.0"

0 commit comments

Comments
 (0)