Skip to content

Commit 8375c4a

Browse files
authored
Merge pull request #3062 from nexB/fix-PythonInstalledWheelMetadataFile-assign_package_to_resources
Fix issues in `PythonInstalledWheelMetadataFile.assign_package_to_resources()`
2 parents c8cdca3 + 1abd495 commit 8375c4a

File tree

17 files changed

+837
-115
lines changed

17 files changed

+837
-115
lines changed

src/packagedcode/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,12 @@ def compute_normalized_license(declared_license, expression_symbols=None):
805805

806806
def add_to_package(package_uid, resource, codebase):
807807
"""
808-
Append `package_uid` to `resource.for_packages`, if the attribute exists.
808+
Append `package_uid` to `resource.for_packages`, if the attribute exists and
809+
`package_uid` is not already in `resource.for_packages`.
809810
"""
810811
if hasattr(resource, 'for_packages') and isinstance(resource.for_packages, list):
812+
if package_uid in resource.for_packages:
813+
return
811814
resource.for_packages.append(package_uid)
812815
resource.save(codebase)
813816

src/packagedcode/pypi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
316316
Assign files to package for an installed wheel. This requires a bit
317317
of navigation around as the files can be in multiple places.
318318
"""
319-
site_packages = resource.parent(codebase).parent(codebase).parent(codebase)
319+
site_packages = resource.parent(codebase).parent(codebase)
320320
if not site_packages:
321321
return
322322
package_data = resource.package_data
@@ -342,7 +342,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
342342
cannot_resolve = False
343343
ref_resource = None
344344
while path_ref.startswith('..'):
345-
_, _, path_ref.partition('../')
345+
_, _, path_ref = path_ref.partition('../')
346346
ref_resource = site_packages.parent(codebase)
347347
if not ref_resource:
348348
cannot_resolve = True

tests/packagedcode/data/debian/basic-rootfs-expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@
319319
}
320320
],
321321
"for_packages": [
322-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
323322
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
324323
],
325324
"scan_errors": []

tests/packagedcode/data/debian/debian-container-layer.tar.xz.get-installed-expected.json

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -359,58 +359,6 @@
359359
}
360360
],
361361
"for_packages": [
362-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
363-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
364-
],
365-
"scan_errors": []
366-
},
367-
{
368-
"path": "debian-container-layer.tar.xz/usr/share/doc/libndp0/copyright",
369-
"type": "file",
370-
"package_data": [
371-
{
372-
"type": "deb",
373-
"namespace": null,
374-
"name": "libndp0",
375-
"version": null,
376-
"qualifiers": {},
377-
"subpath": null,
378-
"primary_language": null,
379-
"description": null,
380-
"release_date": null,
381-
"parties": [],
382-
"keywords": [],
383-
"homepage_url": null,
384-
"download_url": null,
385-
"size": null,
386-
"sha1": null,
387-
"md5": null,
388-
"sha256": null,
389-
"sha512": null,
390-
"bug_tracking_url": null,
391-
"code_view_url": null,
392-
"vcs_url": null,
393-
"copyright": "Copyright 2013 Jiri Pirko <jiri@resnulli.us>\nCopyright 2014 Andrew Ayer <agwa@andrewayer.name>",
394-
"license_expression": "(lgpl-2.1-plus AND lgpl-2.1-plus AND lgpl-2.1) AND (lgpl-2.1-plus AND lgpl-2.1-plus AND lgpl-2.1)",
395-
"declared_license": [
396-
"LGPL-2.1+",
397-
"LGPL-2.1+",
398-
"LGPL-2.1+"
399-
],
400-
"notice_text": null,
401-
"source_packages": [],
402-
"file_references": [],
403-
"extra_data": {},
404-
"dependencies": [],
405-
"repository_homepage_url": null,
406-
"repository_download_url": null,
407-
"api_data_url": null,
408-
"datasource_id": "debian_copyright_in_package",
409-
"purl": "pkg:deb/libndp0"
410-
}
411-
],
412-
"for_packages": [
413-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
414362
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
415363
],
416364
"scan_errors": []

tests/packagedcode/data/debian/debian-container-layer.tar.xz.scan-expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@
333333
}
334334
],
335335
"for_packages": [
336-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
337336
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
338337
],
339338
"scan_errors": []

tests/packagedcode/data/plugin/get_installed_packages-expected.json

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -359,58 +359,6 @@
359359
}
360360
],
361361
"for_packages": [
362-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
363-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
364-
],
365-
"scan_errors": []
366-
},
367-
{
368-
"path": "basic-rootfs.tar.gz/usr/share/doc/libndp0/copyright",
369-
"type": "file",
370-
"package_data": [
371-
{
372-
"type": "deb",
373-
"namespace": null,
374-
"name": "libndp0",
375-
"version": null,
376-
"qualifiers": {},
377-
"subpath": null,
378-
"primary_language": null,
379-
"description": null,
380-
"release_date": null,
381-
"parties": [],
382-
"keywords": [],
383-
"homepage_url": null,
384-
"download_url": null,
385-
"size": null,
386-
"sha1": null,
387-
"md5": null,
388-
"sha256": null,
389-
"sha512": null,
390-
"bug_tracking_url": null,
391-
"code_view_url": null,
392-
"vcs_url": null,
393-
"copyright": "Copyright 2013 Jiri Pirko <jiri@resnulli.us>\nCopyright 2014 Andrew Ayer <agwa@andrewayer.name>",
394-
"license_expression": "(lgpl-2.1-plus AND lgpl-2.1-plus AND lgpl-2.1) AND (lgpl-2.1-plus AND lgpl-2.1-plus AND lgpl-2.1)",
395-
"declared_license": [
396-
"LGPL-2.1+",
397-
"LGPL-2.1+",
398-
"LGPL-2.1+"
399-
],
400-
"notice_text": null,
401-
"source_packages": [],
402-
"file_references": [],
403-
"extra_data": {},
404-
"dependencies": [],
405-
"repository_homepage_url": null,
406-
"repository_download_url": null,
407-
"api_data_url": null,
408-
"datasource_id": "debian_copyright_in_package",
409-
"purl": "pkg:deb/libndp0"
410-
}
411-
],
412-
"for_packages": [
413-
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758",
414362
"pkg:deb/libndp0@1.4-2ubuntu0.16.04.1?architecture=amd64&uuid=fixed-uid-done-for-testing-5642512d1758"
415363
],
416364
"scan_errors": []

tests/packagedcode/data/pypi/site-packages/site-packages-expected.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,18 @@
254254
"path": "lib/python3.9/site-packages/click-8.0.4.dist-info/INSTALLER",
255255
"type": "file",
256256
"package_data": [],
257-
"for_packages": [],
257+
"for_packages": [
258+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
259+
],
258260
"scan_errors": []
259261
},
260262
{
261263
"path": "lib/python3.9/site-packages/click-8.0.4.dist-info/LICENSE.rst",
262264
"type": "file",
263265
"package_data": [],
264-
"for_packages": [],
266+
"for_packages": [
267+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
268+
],
265269
"scan_errors": []
266270
},
267271
{
@@ -736,28 +740,36 @@
736740
"path": "lib/python3.9/site-packages/click-8.0.4.dist-info/RECORD",
737741
"type": "file",
738742
"package_data": [],
739-
"for_packages": [],
743+
"for_packages": [
744+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
745+
],
740746
"scan_errors": []
741747
},
742748
{
743749
"path": "lib/python3.9/site-packages/click-8.0.4.dist-info/WHEEL",
744750
"type": "file",
745751
"package_data": [],
746-
"for_packages": [],
752+
"for_packages": [
753+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
754+
],
747755
"scan_errors": []
748756
},
749757
{
750758
"path": "lib/python3.9/site-packages/click-8.0.4.dist-info/top_level.txt",
751759
"type": "file",
752760
"package_data": [],
753-
"for_packages": [],
761+
"for_packages": [
762+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
763+
],
754764
"scan_errors": []
755765
},
756766
{
757767
"path": "lib/python3.9/site-packages/click/core.py",
758768
"type": "file",
759769
"package_data": [],
760-
"for_packages": [],
770+
"for_packages": [
771+
"pkg:pypi/click@8.0.4?uuid=fixed-uid-done-for-testing-5642512d1758"
772+
],
761773
"scan_errors": []
762774
},
763775
{

0 commit comments

Comments
 (0)