Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/packagedcode/nuget.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,21 @@ def parse(cls, location, package_only=False):
urls = get_urls(name, version)

extracted_license_statement = None
# See https://docs.microsoft.com/en-us/nuget/reference/nuspec#license
# This is a SPDX license expression

if 'license' in nuspec:
extracted_license_statement = nuspec.get('license')
# Deprecated and not a license expression, just a URL
license_value = nuspec.get('license')

if isinstance(license_value, dict):
license_type = license_value.get('@type', 'expression')
license_text = license_value.get('#text', '')

if license_type == 'file':
extracted_license_statement = f"See file at {license_text}"
else:
extracted_license_statement = license_text
else:
extracted_license_statement = license_value

elif 'licenseUrl' in nuspec:
extracted_license_statement = nuspec.get('licenseUrl')

Expand Down
17 changes: 17 additions & 0 deletions tests/packagedcode/data/nuget/python.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>python</id>
<version>3.13.7</version>
<title>Python</title>
<authors>Python Software Foundation</authors>
<owners>python</owners>
<license type="file">tools\LICENSE.txt</license>
<projectUrl>https://www.python.org/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Python is a programming language that lets you work quickly and integrate systems more effectively.</description>
<summary>Python programming language</summary>
<copyright>Copyright (c) Python Software Foundation</copyright>
<tags>python programming</tags>
</metadata>
</package>
59 changes: 59 additions & 0 deletions tests/packagedcode/data/nuget/python.nuspec-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"type": "nuget",
"namespace": null,
"name": "python",
"version": "3.13.7",
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": "Python\nPython is a programming language that lets you work quickly and integrate systems more effectively.",
"release_date": null,
"parties": [
{
"type": null,
"role": "author",
"name": "Python Software Foundation",
"email": null,
"url": null
},
{
"type": null,
"role": "owner",
"name": "python",
"email": null,
"url": null
}
],
"keywords": [],
"homepage_url": "https://www.python.org/",
"download_url": null,
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": "Copyright (c) Python Software Foundation",
"holder": null,
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": "See file at tools\\LICENSE.txt",
"notice_text": null,
"source_packages": [],
"extra_data": {},
"repository_homepage_url": "https://www.nuget.org/packages/python/3.13.7",
"repository_download_url": "https://www.nuget.org/api/v2/package/python/3.13.7",
"api_data_url": "https://api.nuget.org/v3/registration3/python/3.13.7.json",
"package_uid": "pkg:nuget/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"datafile_path": "python.nuspec",
"datasource_id": "nuget_nupsec",
"purl": "pkg:nuget/[email protected]"
}
]
84 changes: 84 additions & 0 deletions tests/packagedcode/data/nuget/python.nuspec-test-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[
{
"type": "nuget",
"namespace": null,
"name": "python",
"version": "3.13.7",
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": "Python programming language\nPython is a programming language that lets you work quickly and integrate systems more effectively.",
"release_date": null,
"parties": [
{
"type": null,
"role": "author",
"name": "Python Software Foundation",
"email": null,
"url": null
},
{
"type": null,
"role": "owner",
"name": "python",
"email": null,
"url": null
}
],
"keywords": [],
"homepage_url": "https://www.python.org/",
"download_url": null,
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": "Copyright (c) Python Software Foundation",
"holder": "Python Software Foundation",
"declared_license_expression": "unknown",
"declared_license_expression_spdx": "LicenseRef-scancode-unknown",
"license_detections": [
{
"license_expression": "unknown",
"license_expression_spdx": "LicenseRef-scancode-unknown",
"matches": [
{
"license_expression": "unknown",
"license_expression_spdx": "LicenseRef-scancode-unknown",
"from_file": null,
"start_line": 1,
"end_line": 1,
"matcher": "5-undetected",
"score": 100.0,
"matched_length": 7,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "package-manifest-unknown-e91aadf36fd5e8ab91355cccd925409b03844ade",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/package-manifest-unknown-e91aadf36fd5e8ab91355cccd925409b03844ade",
"matched_text": "license See file at tools\\LICENSE.txt"
}
],
"identifier": "unknown-5b6b489f-c7ed-f7c7-c8c3-42de924ad570"
}
],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": "See file at tools\\LICENSE.txt",
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": false,
"is_virtual": false,
"extra_data": {},
"dependencies": [],
"repository_homepage_url": "https://www.nuget.org/packages/python/3.13.7",
"repository_download_url": "https://www.nuget.org/api/v2/package/python/3.13.7",
"api_data_url": "https://api.nuget.org/v3/registration3/python/3.13.7.json",
"datasource_id": "nuget_nupsec",
"purl": "pkg:nuget/[email protected]"
}
]
Loading