Skip to content

Commit

Permalink
fix: normalize license expression
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 22, 2024
1 parent 521b7ea commit 591a14d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ repos:
- ninja
- nox
- orjson
- packaging
- packaging>=24.2
- pytest
- pytest-subprocess
- rich
Expand Down
13 changes: 13 additions & 0 deletions src/scikit_build_core/build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,17 @@ def get_standard_metadata(
msg = "Multiple lines in project.description are not supported; this is supposed to be a one line summary"
raise ValueError(msg)

# Validate license if possible.
if isinstance(metadata.license, str):
try:
import packaging.licenses

metadata.license = packaging.licenses.canonicalize_license_expression(
metadata.license
)
except ImportError:
logger.warning(
"Packaging 24.2+ required for license normalization. Please update (Python 3.8+ required)"
)

return metadata
11 changes: 11 additions & 0 deletions tests/test_prepare_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ def test_multiline_description():
},
settings=ScikitBuildSettings(minimum_version=Version("0.8")),
)


def test_license_normalization():
pytest.importorskip("packaging.licenses")
metadata = get_standard_metadata(
pyproject_dict={
"project": {"name": "hello", "version": "1.1.1", "license": "ApacHE-2.0"}
},
settings=ScikitBuildSettings(),
)
assert metadata.license == "Apache-2.0"

0 comments on commit 591a14d

Please sign in to comment.