Skip to content

Commit 0066f92

Browse files
authored
Convert the declared_license field value in resolve_pypi_packages #1598 (#1645)
Signed-off-by: tdruez <[email protected]>
1 parent c5a0609 commit 0066f92

File tree

4 files changed

+209
-1
lines changed

4 files changed

+209
-1
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
v34.10.1 (unreleased)
5+
---------------------
6+
7+
- Convert the ``declared_license`` field value return by ``python-inspector`` in
8+
``resolve_pypi_packages``.
9+
Resolving requirements.txt files will now return proper license data.
10+
https://github.com/aboutcode-org/scancode.io/issues/1598
11+
412
v34.10.0 (2025-03-21)
513
---------------------
614

scanpipe/pipes/resolve.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ def resolve_pypi_packages(input_location):
199199
prefer_source=True,
200200
)
201201

202-
return inspector_output.packages
202+
packages = inspector_output.packages
203+
204+
# python-inspector returns the `extracted_license_statement` under the
205+
# `declared_license` field.
206+
for package in packages:
207+
package["extracted_license_statement"] = package.get("declared_license", "")
208+
209+
return packages
203210

204211

205212
def resolve_about_package(input_location):
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"headers": {
3+
"tool_name": "python-inspector",
4+
"tool_homepageurl": "https://github.com/aboutcode-org/python-inspector",
5+
"tool_version": "0.13.0",
6+
"options": [
7+
"--json -",
8+
"--operating-system linux",
9+
"--python-version 3.12",
10+
"--specifier pip==25.0.1"
11+
],
12+
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/aboutcode-org/python-inspector/ for support and download.",
13+
"warnings": [],
14+
"errors": []
15+
},
16+
"files": [],
17+
"packages": [
18+
{
19+
"type": "pypi",
20+
"namespace": null,
21+
"name": "pip",
22+
"version": "25.0.1",
23+
"qualifiers": {},
24+
"subpath": null,
25+
"primary_language": "Python",
26+
"description": "The PyPA recommended tool for installing Python packages.\npip - The Python Package Installer\n==================================\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n :alt: PyPI\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/pip\n :target: https://pypi.org/project/pip\n :alt: PyPI - Python Version\n\n.. |docs-badge| image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n :alt: Documentation\n\n|pypi-version| |python-versions| |docs-badge|\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md",
27+
"release_date": "2025-02-09T17:14:01",
28+
"parties": [
29+
{
30+
"type": "person",
31+
"role": "author",
32+
"name": null,
33+
"email": "The pip developers <[email protected]>",
34+
"url": null
35+
}
36+
],
37+
"keywords": [
38+
"Development Status :: 5 - Production/Stable",
39+
"Intended Audience :: Developers",
40+
"Programming Language :: Python",
41+
"Programming Language :: Python :: 3",
42+
"Programming Language :: Python :: 3 :: Only",
43+
"Programming Language :: Python :: 3.10",
44+
"Programming Language :: Python :: 3.11",
45+
"Programming Language :: Python :: 3.12",
46+
"Programming Language :: Python :: 3.13",
47+
"Programming Language :: Python :: 3.8",
48+
"Programming Language :: Python :: 3.9",
49+
"Programming Language :: Python :: Implementation :: CPython",
50+
"Programming Language :: Python :: Implementation :: PyPy",
51+
"Topic :: Software Development :: Build Tools"
52+
],
53+
"homepage_url": null,
54+
"download_url": "https://files.pythonhosted.org/packages/c9/bc/b7db44f5f39f9d0494071bddae6880eb645970366d0a200022a1a93d57f5/pip-25.0.1-py3-none-any.whl",
55+
"size": 1841526,
56+
"sha1": null,
57+
"md5": "99f43f22d5321305507b804a2be662c0",
58+
"sha256": "c46efd13b6aa8279f33f2864459c8ce587ea6a1a59ee20de055868d8f7688f7f",
59+
"sha512": null,
60+
"bug_tracking_url": null,
61+
"code_view_url": "https://github.com/pypa/pip",
62+
"vcs_url": null,
63+
"copyright": null,
64+
"license_expression": null,
65+
"declared_license": {
66+
"license": "MIT",
67+
"classifiers": [
68+
"License :: OSI Approved :: MIT License"
69+
]
70+
},
71+
"notice_text": null,
72+
"source_packages": [],
73+
"file_references": [],
74+
"extra_data": {},
75+
"dependencies": [],
76+
"repository_homepage_url": null,
77+
"repository_download_url": null,
78+
"api_data_url": "https://pypi.org/pypi/pip/25.0.1/json",
79+
"datasource_id": null,
80+
"purl": "pkg:pypi/[email protected]"
81+
},
82+
{
83+
"type": "pypi",
84+
"namespace": null,
85+
"name": "pip",
86+
"version": "25.0.1",
87+
"qualifiers": {},
88+
"subpath": null,
89+
"primary_language": "Python",
90+
"description": "The PyPA recommended tool for installing Python packages.\npip - The Python Package Installer\n==================================\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n :alt: PyPI\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/pip\n :target: https://pypi.org/project/pip\n :alt: PyPI - Python Version\n\n.. |docs-badge| image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n :alt: Documentation\n\n|pypi-version| |python-versions| |docs-badge|\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md",
91+
"release_date": "2025-02-09T17:14:04",
92+
"parties": [
93+
{
94+
"type": "person",
95+
"role": "author",
96+
"name": null,
97+
"email": "The pip developers <[email protected]>",
98+
"url": null
99+
}
100+
],
101+
"keywords": [
102+
"Development Status :: 5 - Production/Stable",
103+
"Intended Audience :: Developers",
104+
"Programming Language :: Python",
105+
"Programming Language :: Python :: 3",
106+
"Programming Language :: Python :: 3 :: Only",
107+
"Programming Language :: Python :: 3.10",
108+
"Programming Language :: Python :: 3.11",
109+
"Programming Language :: Python :: 3.12",
110+
"Programming Language :: Python :: 3.13",
111+
"Programming Language :: Python :: 3.8",
112+
"Programming Language :: Python :: 3.9",
113+
"Programming Language :: Python :: Implementation :: CPython",
114+
"Programming Language :: Python :: Implementation :: PyPy",
115+
"Topic :: Software Development :: Build Tools"
116+
],
117+
"homepage_url": null,
118+
"download_url": "https://files.pythonhosted.org/packages/70/53/b309b4a497b09655cb7e07088966881a57d082f48ac3cb54ea729fd2c6cf/pip-25.0.1.tar.gz",
119+
"size": 1950850,
120+
"sha1": null,
121+
"md5": "1bf81564bf9738efbe48439c230f25bf",
122+
"sha256": "88f96547ea48b940a3a385494e181e29fb8637898f88d88737c5049780f196ea",
123+
"sha512": null,
124+
"bug_tracking_url": null,
125+
"code_view_url": "https://github.com/pypa/pip",
126+
"vcs_url": null,
127+
"copyright": null,
128+
"license_expression": null,
129+
"declared_license": {
130+
"license": "MIT",
131+
"classifiers": [
132+
"License :: OSI Approved :: MIT License"
133+
]
134+
},
135+
"notice_text": null,
136+
"source_packages": [],
137+
"file_references": [],
138+
"extra_data": {},
139+
"dependencies": [],
140+
"repository_homepage_url": null,
141+
"repository_download_url": null,
142+
"api_data_url": "https://pypi.org/pypi/pip/25.0.1/json",
143+
"datasource_id": null,
144+
"purl": "pkg:pypi/[email protected]"
145+
}
146+
],
147+
"resolved_dependencies_graph": [
148+
{
149+
"package": "pkg:pypi/[email protected]",
150+
"dependencies": []
151+
}
152+
]
153+
}

scanpipe/tests/pipes/test_resolve.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/nexB/scancode.io for support and download.
2222

23+
import json
2324
from pathlib import Path
2425
from unittest import mock
2526

@@ -31,6 +32,7 @@
3132
from scanpipe.pipes.input import copy_inputs
3233
from scanpipe.pipes.scancode import extract_archives
3334
from scanpipe.tests import make_package
35+
from scanpipe.tests import make_project
3436
from scanpipe.tests import package_data1
3537

3638

@@ -111,6 +113,44 @@ def test_scanpipe_pipes_resolve_get_packages_from_manifest(self):
111113
}
112114
self.assertEqual([expected], packages)
113115

116+
@mock.patch("scanpipe.pipes.resolve.resolve_dependencies")
117+
def test_scanpipe_pipes_resolve_resolve_pypi_packages(self, mock_resolve):
118+
# Generated with:
119+
# $ python-inspector --python-version 3.12 --operating-system linux \
120+
# --specifier pip==25.0.1 --json -
121+
inspector_output_location = (
122+
self.data / "resolve" / "python_inspector_resolve_dependencies.json"
123+
)
124+
with open(inspector_output_location) as f:
125+
inspector_output = json.loads(f.read())
126+
127+
mock_resolve.return_value = mock.Mock(packages=inspector_output["packages"])
128+
129+
packages = resolve.resolve_pypi_packages("")
130+
self.assertEqual(2, len(packages))
131+
package_data = packages[0]
132+
self.assertEqual("pip", package_data["name"])
133+
self.assertEqual("25.0.1", package_data["version"])
134+
self.assertEqual("Python", package_data["primary_language"])
135+
self.assertIsNone(package_data["license_expression"])
136+
expected_license = {
137+
"license": "MIT",
138+
"classifiers": ["License :: OSI Approved :: MIT License"],
139+
}
140+
self.assertEqual(expected_license, package_data["extracted_license_statement"])
141+
142+
project = make_project()
143+
resolve.create_packages_and_dependencies(
144+
project=project,
145+
packages=packages,
146+
resolved=True,
147+
)
148+
149+
self.assertEqual(2, project.discoveredpackages.count())
150+
151+
package = project.discoveredpackages.all()[0]
152+
self.assertEqual(str(expected_license), package.extracted_license_statement)
153+
114154
def test_scanpipe_pipes_resolve_resolve_about_packages(self):
115155
input_location = self.manifest_location / "Django-4.0.8-py3-none-any.whl.ABOUT"
116156
package = resolve.resolve_about_packages(str(input_location))

0 commit comments

Comments
 (0)