Repository navigation
feat(sbom): populate license fields from wheel metadata #1457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mprpic
wants to merge
4
commits into
python-wheel-build:main
Choose a base branch
from
mprpic:sbom-license-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc49b44
feat(pkgmetadata): detect declared license with SPDX ambiguity info
mprpic f51b9c3
feat(sbom): populate license fields from wheel metadata
mprpic 0a4167a
docs(sbom): describe SBOM license fields
mprpic 0876e82
test(e2e): check SBOM license fields
mprpic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| sbom: | ||
| supplier: "Organization: ExampleCo" | ||
| namespace: "https://sbom.test" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| # -*- indent-tabs-mode: nil; tab-width: 2; sh-indentation: 2; -*- | ||
|
|
||
| # Test that the SBOM embedded in each built wheel carries the license the | ||
| # wheel declares in its METADATA (issue #1378). | ||
| # | ||
| # idna 3.6 only has the ambiguous "BSD License" classifier, so it must get | ||
| # a LicenseRef with extracted licensing info. tomli 2.0.1 has the "MIT | ||
| # License" classifier, which maps cleanly to MIT. | ||
|
|
||
| SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
| source "$SCRIPTDIR/common.sh" | ||
|
|
||
| fromager \ | ||
| --log-file="$OUTDIR/bootstrap.log" \ | ||
| --error-log-file="$OUTDIR/fromager-errors.log" \ | ||
| --sdists-repo="$OUTDIR/sdists-repo" \ | ||
| --wheels-repo="$OUTDIR/wheels-repo" \ | ||
| --work-dir="$OUTDIR/work-dir" \ | ||
| --settings-file="$SCRIPTDIR/sbom_settings.yaml" \ | ||
| bootstrap 'idna==3.6' 'tomli==2.0.1' | ||
|
|
||
| find "$OUTDIR/wheels-repo/downloads/" -name '*.whl' | ||
|
|
||
| python3 - "$OUTDIR/wheels-repo/downloads" <<'EOF' | ||
| import json | ||
| import pathlib | ||
| import re | ||
| import sys | ||
| import zipfile | ||
|
|
||
| downloads = pathlib.Path(sys.argv[1]) | ||
| failures = [] | ||
|
|
||
|
|
||
| def sbom_of(wheel): | ||
| with zipfile.ZipFile(wheel) as zf: | ||
| (name,) = [n for n in zf.namelist() if n.endswith(".dist-info/sboms/fromager.spdx.json")] | ||
| return json.loads(zf.read(name)) | ||
|
|
||
|
|
||
| def check(condition, message): | ||
| if not condition: | ||
| failures.append(message) | ||
|
|
||
|
|
||
| # invariants for every built wheel, including build dependencies | ||
| wheels = sorted(downloads.glob("*.whl")) | ||
| check(wheels, f"no wheels found in {downloads}") | ||
| for wheel in wheels: | ||
| doc = sbom_of(wheel) | ||
| wheel_pkg, upstream_pkg = doc["packages"] | ||
| for key in ("licenseDeclared", "licenseConcluded", "licenseComments"): | ||
| check(key in wheel_pkg and key in upstream_pkg, f"{wheel.name}: {key} missing from a package") | ||
| check(wheel_pkg.get(key) == upstream_pkg.get(key), f"{wheel.name}: {key} differs between packages") | ||
| check(wheel_pkg.get("licenseConcluded") == "NOASSERTION", f"{wheel.name}: licenseConcluded is not NOASSERTION") | ||
| declared_ids = {e["licenseId"] for e in doc.get("hasExtractedLicensingInfos", [])} | ||
| for ref in re.findall(r"LicenseRef-[A-Za-z0-9.\-]+", wheel_pkg.get("licenseDeclared", "")): | ||
| check(ref in declared_ids, f"{wheel.name}: {ref} has no extracted licensing info") | ||
|
|
||
| # ambiguous classifier: LicenseRef plus extracted licensing info | ||
| idna = sbom_of(next(downloads.glob("idna-3.6-*.whl"))) | ||
| idna_ref = "LicenseRef-license-osi-approved-bsd-license-a9d12a80" | ||
| idna_pkg = idna["packages"][0] | ||
| check(idna_pkg.get("licenseDeclared") == idna_ref, f"idna: licenseDeclared is {idna_pkg.get('licenseDeclared')!r}") | ||
| check( | ||
| idna.get("hasExtractedLicensingInfos") == [{"licenseId": idna_ref, "extractedText": "License :: OSI Approved :: BSD License"}], | ||
| f"idna: unexpected hasExtractedLicensingInfos {idna.get('hasExtractedLicensingInfos')!r}", | ||
| ) | ||
| check("(License classifiers)" in idna_pkg.get("licenseComments", ""), "idna: comment does not name the source") | ||
|
|
||
| # unambiguous classifier: plain SPDX id, no extracted licensing info | ||
| tomli = sbom_of(next(downloads.glob("tomli-2.0.1-*.whl"))) | ||
| tomli_pkg = tomli["packages"][0] | ||
| check(tomli_pkg.get("licenseDeclared") == "MIT", f"tomli: licenseDeclared is {tomli_pkg.get('licenseDeclared')!r}") | ||
| check("hasExtractedLicensingInfos" not in tomli, "tomli: unexpected hasExtractedLicensingInfos") | ||
|
|
||
| for failure in failures: | ||
| print(f"FAIL: {failure}", file=sys.stderr) | ||
| print(f"checked {len(wheels)} wheels, {len(failures)} failure(s)") | ||
| sys.exit(1 if failures else 0) | ||
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.