Skip to content

Commit

Permalink
Update deprecated code #411
Browse files Browse the repository at this point in the history
    * Normalize package_uids before comparing results in tests
    * Update expected test results

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed May 9, 2022
1 parent a029c26 commit 774c5b7
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 347 deletions.
20 changes: 11 additions & 9 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,24 @@ def create_codebase_resources(project, scanned_codebase):
)

# associate DiscoveredPackage to Resource, if applicable
for package_uid in scanned_resource.for_packages:
package = DiscoveredPackage.objects.get(
extra_data__contains={"package_uids": [package_uid]}
)
set_codebase_resource_for_package(
codebase_resource=cbr, discovered_package=package
)
if hasattr(scanned_resource, "for_packages"):
for package_uid in scanned_resource.for_packages:
package = DiscoveredPackage.objects.get(
extra_data__contains={"package_uids": [package_uid]}
)
set_codebase_resource_for_package(
codebase_resource=cbr, discovered_package=package
)


def create_discovered_packages(project, scanned_codebase):
"""
Saves the packages of a ScanCode `scanned_codebase` scancode.resource.Codebase
object to the database as a DiscoveredPackage of `project`.
"""
for package_data in scanned_codebase.attributes.packages:
pipes.update_or_create_package(project, package_data)
if hasattr(scanned_codebase.attributes, "packages"):
for package_data in scanned_codebase.attributes.packages:
pipes.update_or_create_package(project, package_data)


def set_codebase_resource_for_package(codebase_resource, discovered_package):
Expand Down
9 changes: 6 additions & 3 deletions scanpipe/pipes/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from django.db.models import Q

from packagedcode import win_reg
from packagedcode.models import Package

from scanpipe import pipes

Expand Down Expand Up @@ -150,7 +151,8 @@ def _tag_python_software(project):
q_objects = [~Q(rootfs_path__icontains="site-packages")]

for python_path, python_version in python_versions_by_path.items():
python_package = win_reg.InstalledWindowsProgram(
python_package = Package(
type="windows-program",
name="Python",
version=python_version,
license_expression="python",
Expand Down Expand Up @@ -194,7 +196,8 @@ def _tag_openjdk_software(project):
openjdk_versions_by_path[openjdk_root_path] = openjdk_version

for openjdk_path, openjdk_version in openjdk_versions_by_path.items():
openjdk_package = win_reg.InstalledWindowsProgram(
openjdk_package = Package(
type="windows-program",
name="OpenJDK",
version=openjdk_version,
license_expression="gpl-2.0 WITH oracle-openjdk-classpath-exception-2.0",
Expand Down Expand Up @@ -270,7 +273,7 @@ def tag_program_files(project):
program_files_dirname_by_path[program_files_subdir] = dirname

for root_dir, root_dir_name in program_files_dirname_by_path.items():
package = win_reg.InstalledWindowsProgram(name=root_dir_name, version="nv")
package = Package(type="windows-program", name=root_dir_name, version="nv")
tag_installed_package_files(
project=project,
root_dir_pattern=root_dir,
Expand Down
9 changes: 5 additions & 4 deletions scanpipe/tests/data/is-npm-1.0.0_scan_codebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"is_runtime": false,
"is_optional": true,
"is_resolved": false,
"requirement": "0.0.3"
"resolved_package": {},
"extracted_requirement": "0.0.3"
}
],
"keywords": [
Expand Down Expand Up @@ -182,7 +183,7 @@
},
{
"for_packages": [
"pkg:npm/[email protected]"
"pkg:npm/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"path": "is-npm-1.0.0.tgz-extract/package/package.json",
"sha1": "943efb8abda9b9cdaa4ea73f5709563b948af50b",
Expand Down Expand Up @@ -216,14 +217,14 @@
"extra_data": {},
"copyrights": [
{
"value": "(c) Sindre Sorhus (http://sindresorhus.com)",
"end_line": 30,
"copyright": "(c) Sindre Sorhus (http://sindresorhus.com)",
"start_line": 30
}
],
"holders": [
{
"value": "Sindre Sorhus",
"holder": "Sindre Sorhus",
"end_line": 30,
"start_line": 30
}
Expand Down
Loading

0 comments on commit 774c5b7

Please sign in to comment.