-
Notifications
You must be signed in to change notification settings - Fork 498
feat(ci-scripts): utility scripts for license updates and SBOM #1548
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
Merged
rapids-bot
merged 7 commits into
NVIDIA:develop
from
willkill07:wkk_add-license-support-scripts
Feb 3, 2026
+2,197
−475
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e7cd36a
feat(ci-scripts): utility scripts for license updates and SBOM
willkill07 d2b57f2
add examples to root uv.lock; update coderabbit and cursor rules
willkill07 dec6c7e
update precommit
willkill07 eb80a78
update uv.lock
willkill07 1672112
use specific uv tag
willkill07 00b3add
don't precommit uv.lock yet
willkill07 e7a10b4
update scripts to handle errors cleaner
willkill07 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
Some comments aren't visible on the classic Files Changed page.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Compare dependency licenses between the current and base `uv.lock`. | ||
|
|
||
| This script fetches the base lockfile from the GitHub repository and compares it | ||
| to the local `uv.lock`. It prints added, removed, and changed third-party | ||
| packages and includes license data where possible. | ||
|
|
||
| The output is intended for human review during CI checks, not as a machine- | ||
| parsable report. | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| import tomllib | ||
| import urllib.request | ||
|
|
||
|
|
||
| def pypi_license(name: str, version: str | None = None) -> str: | ||
| """Resolve a package license from PyPI metadata. | ||
|
|
||
| Args: | ||
| name: Distribution name on PyPI. | ||
| version: Optional version pin used to query version-specific metadata. | ||
|
|
||
| Returns: | ||
| A best-effort license string from the available metadata fields. | ||
| """ | ||
| # Use version-specific metadata when available to avoid mismatches. | ||
| try: | ||
| url = f"https://pypi.org/pypi/{name}/json" if version is None else f"https://pypi.org/pypi/{name}/{version}/json" | ||
| with urllib.request.urlopen(url) as r: | ||
| data = json.load(r) | ||
| except Exception: | ||
| return "(License not found)" | ||
|
|
||
| info = data.get("info", {}) | ||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| candidates = [] | ||
| lic = (info.get("license_expression") or "").strip() | ||
| if lic: | ||
| candidates.append(lic) | ||
| classifiers = info.get("classifiers") or [] | ||
| lic_cls = [c for c in classifiers if c.startswith("License ::")] | ||
| if lic_cls: | ||
| candidates.append("; ".join(lic_cls)) | ||
| lic = (info.get("license") or "").strip() | ||
| if lic: | ||
| candidates.append(lic) | ||
|
|
||
| if candidates: | ||
| return min(candidates, key=len) | ||
| return "(License not found)" | ||
|
|
||
|
|
||
| def main(base_branch: str) -> None: | ||
| """Compare the local `uv.lock` against a base branch lockfile. | ||
|
|
||
| Args: | ||
| base_branch: Git branch name used to locate the base `uv.lock` file. | ||
| """ | ||
| # Read the current lockfile from the workspace. | ||
| with open("uv.lock", "rb") as f: | ||
| head = tomllib.load(f) | ||
|
|
||
| # Fetch the reference lockfile from GitHub for comparison. | ||
| try: | ||
| with urllib.request.urlopen( | ||
| f"https://raw.githubusercontent.com/NVIDIA/NeMo-Agent-Toolkit/{base_branch}/uv.lock") as f: | ||
| base = tomllib.load(f) | ||
| except Exception: | ||
| print(f"Failed to fetch base lockfile from GitHub: {base_branch}") | ||
| return | ||
|
|
||
| # Index package metadata by name for easy diffing. | ||
| head_packages = {pkg["name"]: pkg for pkg in head["package"]} | ||
| base_packages = {pkg["name"]: pkg for pkg in base["package"]} | ||
|
|
||
| added = head_packages.keys() - base_packages.keys() | ||
| removed = base_packages.keys() - head_packages.keys() | ||
| intersection = head_packages.keys() & base_packages.keys() | ||
|
|
||
| # Track third-party dependency changes only (skip internal `nvidia-nat*`). | ||
| added_packages = {pkg: head_packages[pkg] for pkg in added} | ||
| removed_packages = {pkg: base_packages[pkg] for pkg in removed} | ||
| changed_packages = {pkg: head_packages[pkg] for pkg in intersection if not pkg.startswith("nvidia-nat")} | ||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if added_packages: | ||
| print("Added packages:") | ||
| for pkg in sorted(added_packages.keys()): | ||
| try: | ||
| version = head_packages[pkg]["version"] | ||
| license = pypi_license(pkg, version) | ||
| print(f"- {pkg} {version} {license}") | ||
| except KeyError: | ||
| # "Source" entries lack pinned versions (VCS or local path). | ||
| print(f"- {pkg} (source)") | ||
|
|
||
| if removed_packages: | ||
| print("Removed packages:") | ||
| for pkg in sorted(removed_packages.keys()): | ||
| try: | ||
| version = base_packages[pkg]["version"] | ||
| print(f"- {pkg} {version}") | ||
| except KeyError: | ||
| print(f"- {pkg} (source)") | ||
|
|
||
| printed_header = False | ||
| for pkg in sorted(changed_packages.keys()): | ||
| try: | ||
| head_version = head_packages[pkg]["version"] | ||
| base_version = base_packages[pkg]["version"] | ||
| if head_version == base_version: | ||
| # Only report version or license changes. | ||
| continue | ||
| head_license = pypi_license(pkg, head_version) | ||
| base_license = pypi_license(pkg, base_version) | ||
| if not printed_header: | ||
| print("Changed packages:") | ||
| printed_header = True | ||
| if head_license != base_license: | ||
| print(f"- {pkg} {base_version} -> {head_version} ({base_license} -> {head_license})") | ||
| else: | ||
| print(f"- {pkg} {base_version} -> {head_version}") | ||
| except KeyError: | ||
| if not printed_header: | ||
| print("Changed packages:") | ||
| printed_header = True | ||
| print(f"- {pkg} (source)") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Report third-party dependency license changes between lockfiles.") | ||
| parser.add_argument("--base-branch", type=str, default="develop") | ||
| args = parser.parse_args() | ||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| main(args.base_branch) | ||
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,125 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Generate a tab-separated list of dependency licenses from `uv.lock`. | ||
|
|
||
| The output is stored as `sbom_list.tsv` and includes package name, version, and | ||
| license metadata from PyPI. This is intended for lightweight SBOM checks in CI. | ||
| """ | ||
|
|
||
| import csv | ||
| import json | ||
| import tomllib | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| from tqdm import tqdm | ||
|
|
||
|
|
||
| def pypi_license(name: str, version: str | None = None) -> str: | ||
| """Resolve a package license from PyPI metadata. | ||
|
|
||
| Args: | ||
| name: Distribution name on PyPI. | ||
| version: Optional version pin used to query version-specific metadata. | ||
|
|
||
| Returns: | ||
| A best-effort license string from the available metadata fields. | ||
| """ | ||
| # Use version-specific metadata when available to avoid mismatches. | ||
| try: | ||
| url = f"https://pypi.org/pypi/{name}/json" if version is None else f"https://pypi.org/pypi/{name}/{version}/json" | ||
| with urllib.request.urlopen(url) as r: | ||
| data = json.load(r) | ||
| except Exception: | ||
| return "(License not found)" | ||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| info = data.get("info", {}) | ||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| candidates = [] | ||
| lic = (info.get("license_expression") or "").strip() | ||
| if lic: | ||
| candidates.append(lic) | ||
| classifiers = info.get("classifiers") or [] | ||
| lic_cls = [c for c in classifiers if c.startswith("License ::")] | ||
| if lic_cls: | ||
| candidates.append("; ".join(lic_cls)) | ||
| lic = (info.get("license") or "").strip() | ||
| if lic: | ||
| candidates.append(lic) | ||
|
|
||
| if candidates: | ||
| return min(candidates, key=len) | ||
| return "(License not found)" | ||
|
|
||
|
|
||
| def process_uvlock(uvlock: dict, base_name: str) -> Path: | ||
| """Write a generic license table from a loaded `uv.lock` structure. | ||
|
|
||
| Args: | ||
| uvlock: Parsed `uv.lock` content. | ||
| base_name: Logical label for the source data (kept for compatibility). | ||
|
|
||
willkill07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Returns: | ||
| Path to the generated `licenses.tsv` file. | ||
| """ | ||
| # Keep packages ordered to make diffs stable between runs. | ||
| sorted_packages = sorted(uvlock["package"], key=lambda x: x["name"]) | ||
|
|
||
| with open("licenses.tsv", "w") as f: | ||
| writer = csv.writer(f, delimiter="\t") | ||
| writer.writerow(["Name", "Version", "License"]) | ||
| for pkg in tqdm(sorted_packages, desc="Checking licenses", unit="packages"): | ||
| try: | ||
| name = pkg["name"] | ||
| version = pkg["version"] | ||
| license = pypi_license(name, version) | ||
| writer.writerow([name, version, license]) | ||
| except KeyError: | ||
| # Skip entries that do not have name/version info. | ||
| pass | ||
| return Path("licenses.tsv") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Create `sbom_list.tsv` for third-party license reporting.""" | ||
| # Load the lockfile that captures the dependency graph. | ||
| with open("uv.lock", "rb") as f: | ||
| head = tomllib.load(f) | ||
|
|
||
| # Index packages by name for quick lookups. | ||
| pkgs = {pkg["name"]: pkg for pkg in head["package"]} | ||
|
|
||
| sbom_list = [] | ||
| for pkg in tqdm(pkgs.keys(), desc="Processing packages", unit="packages"): | ||
| try: | ||
| sbom_list.append({ | ||
| "name": pkg, | ||
| "version": pkgs[pkg]["version"], | ||
| "license": pypi_license(pkg, pkgs[pkg]["version"]), | ||
| }) | ||
| except KeyError: | ||
| # Skip entries that do not contain a version field. | ||
| pass | ||
|
|
||
| # Write the final SBOM table in a TSV format to keep it spreadsheet-friendly. | ||
| with open("sbom_list.tsv", "w") as f: | ||
| writer = csv.writer(f, delimiter="\t") | ||
| writer.writerow(["Name", "Version", "License"]) | ||
| for pkg in sbom_list: | ||
| writer.writerow([pkg["name"], pkg["version"], pkg["license"].replace("\n", "\\n")]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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
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.
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.