Skip to content

Commit

Permalink
Return package_uids in for_packages #444
Browse files Browse the repository at this point in the history
    * This is so we are consistent with scancode-toolkit JSON output
    * Update expected test results

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Aug 24, 2022
1 parent 39c9c19 commit 138a43f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 330 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ v31.0.0 (next)

https://github.com/nexB/scancode.io/issues/444

- ``CodebaseResource.for_packages`` now returns a list of
``DiscoveredPackage.package_uid`` or ``DiscoveredPackage.package_url`` if
``DiscoveredPackage.package_uid`` is not present. This is done to reflect the
how scancode-toolkit's JSON output returns ``package_uid``s in the
``for_packages`` field for Resources.

v30.2.0 (2021-12-17)
--------------------

Expand Down
5 changes: 4 additions & 1 deletion scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,10 @@ def for_packages(self):
"""
Returns the list of all discovered packages associated to this resource.
"""
return [str(package) for package in self.discovered_packages.all()]
return [
package.package_uid if package.package_uid else str(package)
for package in self.discovered_packages.all()
]


class DiscoveredPackageQuerySet(PackageURLQuerySetMixin, ProjectRelatedQuerySet):
Expand Down
50 changes: 40 additions & 10 deletions scanpipe/tests/data/asgiref-3.3.0_load_inventory_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false
"is_media": false,
"package_data": []
},
{
"for_packages": [],
Expand All @@ -873,7 +874,8 @@
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false
"is_media": false,
"package_data": []
},
{
"for_packages": [],
Expand All @@ -899,7 +901,8 @@
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false
"is_media": false,
"package_data": []
},
{
"for_packages": [],
Expand Down Expand Up @@ -930,9 +933,9 @@
},
{
"for_packages": [],
"path": "asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/top_level.txt",
"sha1": "612390bd0d0227c009f9c99b479878adf7ac2f23",
"md5": "680e61db4d95c8d9501b7a49fa2bf0b2",
"path": "asgiref-3.3.0-py3-none-any.whl-extract/asgiref/compatibility.py",
"sha1": "9c74e64e9a71903bb227907ea1806eac77e52434",
"md5": "5231077fd0628314246fcba7817b561e",
"extra_data": {},
"copyrights": [],
"holders": [],
Expand All @@ -944,10 +947,37 @@
"status": "",
"tag": "",
"type": "file",
"name": "top_level.txt",
"extension": ".txt",
"programming_language": "",
"mime_type": "text/plain",
"name": "compatibility.py",
"extension": ".py",
"programming_language": "Python",
"mime_type": "text/x-script.python",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false,
"package_data": []
},
{
"for_packages": [],
"path": "asgiref-3.3.0-py3-none-any.whl-extract/asgiref/current_thread_executor.py",
"sha1": "aacf7e5e2e5ba78ccfb67fa10e9e6b22c3935c9b",
"md5": "b4c45f37055d88dd11b15eb4de51b074",
"extra_data": {},
"copyrights": [],
"holders": [],
"authors": [],
"licenses": [],
"license_expressions": [],
"emails": [],
"urls": [],
"status": "",
"tag": "",
"type": "file",
"name": "current_thread_executor.py",
"extension": ".py",
"programming_language": "Python",
"mime_type": "text/x-script.python",
"is_binary": false,
"is_text": true,
"is_archive": false,
Expand Down
52 changes: 0 additions & 52 deletions scanpipe/tests/data/centos_scan_codebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -186626,58 +186626,6 @@
"is_media": false,
"package_data": []
},
{
"for_packages": [],
"path": "centos.tar.gz-extract/a10cf747c363a52be048f884c084a25e03280d54a7ac02e17dbd8c5ad160e9bd/var/lib/rpm/.dbenv.lock",
"sha1": "",
"md5": "",
"extra_data": {},
"copyrights": [],
"holders": [],
"authors": [],
"licenses": [],
"license_expressions": [],
"emails": [],
"urls": [],
"status": "ignored-empty-file",
"tag": "img-c967b7-layer-01-a10cf7",
"type": "file",
"name": ".dbenv.lock",
"extension": ".lock",
"programming_language": "",
"mime_type": "inode/x-empty",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false
},
{
"for_packages": [],
"path": "centos.tar.gz-extract/a10cf747c363a52be048f884c084a25e03280d54a7ac02e17dbd8c5ad160e9bd/var/lib/rpm/.rpm.lock",
"sha1": "",
"md5": "",
"extra_data": {},
"copyrights": [],
"holders": [],
"authors": [],
"licenses": [],
"license_expressions": [],
"emails": [],
"urls": [],
"status": "ignored-empty-file",
"tag": "img-c967b7-layer-01-a10cf7",
"type": "file",
"name": ".rpm.lock",
"extension": ".lock",
"programming_language": "",
"mime_type": "inode/x-empty",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_key_file": false,
"is_media": false
},
{
"for_packages": [
"pkg:rpm/[email protected]?arch=x86_64&uuid=fixed-uid-done-for-testing-5642512d1758"
Expand Down
Loading

0 comments on commit 138a43f

Please sign in to comment.