Skip to content

Commit 7497407

Browse files
Fix test failures from merging develop
Add node_modules as ignored paths for NPM package instance creation. Regenerate test expectations after merging from develop. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 498080b commit 7497407

11 files changed

Lines changed: 406 additions & 568 deletions

File tree

src/packagedcode/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ class PackageInstance:
802802
help='List of files provided by this package.'
803803
)
804804

805+
@property
806+
def ignore_paths(self):
807+
"""
808+
Paths to ignore when looking for other package_data files.
809+
810+
Override the default empty list by defining for each package ecosystems specifically.
811+
"""
812+
return []
813+
805814
def to_dict(self, **kwargs):
806815
"""
807816
Return an dict of primitive Python types.
@@ -889,10 +898,19 @@ def get_other_package_data_for_instance(self, resource, codebase):
889898

890899
parent = resource.parent(codebase)
891900

901+
paths_to_ignore = self.ignore_paths
902+
892903
for resource in parent.walk(codebase):
893904
if resource.is_dir:
894905
continue
895906

907+
if paths_to_ignore:
908+
if any(
909+
path in resource.path
910+
for path in paths_to_ignore
911+
):
912+
continue
913+
896914
filename = file_name(resource.location)
897915
file_patterns = self.get_file_patterns(manifests=self.manifests)
898916
if any(fnmatch.fnmatchcase(filename, pattern) for pattern in file_patterns):

src/packagedcode/npm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ class NpmPackageInstance(NpmPackage, models.PackageInstance):
467467
manifests, lockfiles, build scripts and package-like data, with it's files.
468468
"""
469469

470+
@property
471+
def ignore_paths(self):
472+
return [
473+
"node_modules"
474+
]
475+
470476
@property
471477
def manifests(self):
472478
return [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Resource,type,scan_errors,package__type,package__namespace,package__name,package__version,package__qualifiers,package__subpath,package__primary_language,package__description,package__release_date,package__homepage_url,package__download_url,package__size,package__sha1,package__md5,package__sha256,package__sha512,package__bug_tracking_url,package__code_view_url,package__vcs_url,package__copyright,package__license_expression,package__declared_license,package__notice_text,package__root_path,package__contains_source_code,package__extra_data,package__purl
1+
path,type,scan_errors,package__type,package__namespace,package__name,package__version,package__qualifiers,package__subpath,package__primary_language,package__description,package__release_date,package__homepage_url,package__download_url,package__size,package__sha1,package__md5,package__sha256,package__sha512,package__bug_tracking_url,package__code_view_url,package__vcs_url,package__copyright,package__license_expression,package__declared_license,package__notice_text,package__root_path,package__contains_source_code,package__extra_data,package__purl
22
scan/,directory,,,,,,,,,,,,,,,,,,,,,,,,,,,,
33
scan/package.json,file,,,,,,,,,,,,,,,,,,,,,,,,,,,,
44
scan/package.json,,,npm,,npm,v 2.13.5,,,JavaScript,a package manager for JavaScript,,https://docs.npmjs.com/,https://registry.npmjs.org/npm/-/npm-2.13.5.tgz,,a124386bce4a90506f28ad4b1d1a804a17baaf32,,,,http://github.com/npm/npm/issues,,git+https://github.com/npm/npm.git@fc7bbf03e39cc48a8924b90696d28345a6a90f3c,,artistic-2.0,Artistic-2.0,,,,,pkg:npm/npm@2.13.5

tests/formattedcode/data/cyclonedx/expected.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
"author": "Isaac Z. Schlueter",
1616
"description": "a package manager for JavaScript",
1717
"purl": "pkg:npm/npm@2.13.5",
18-
"hashes": [
19-
{
20-
"alg": "SHA-1",
21-
"content": "a124386bce4a90506f28ad4b1d1a804a17baaf32"
22-
}
23-
],
18+
"hashes": [],
2419
"licenses": [
2520
{
2621
"expression": "Artistic-2.0"

tests/formattedcode/data/cyclonedx/expected.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<author>Isaac Z. Schlueter</author>
1818
<scope>required</scope>
1919
<purl>pkg:npm/npm@2.13.5</purl>
20-
<hashes>
21-
<hash alg="SHA-1">a124386bce4a90506f28ad4b1d1a804a17baaf32</hash>
22-
</hashes>
2320
<licenses>
2421
<expression>Artistic-2.0</expression>
2522
</licenses>

tests/formattedcode/data/cyclonedx/simple/abbrev/package.json renamed to tests/formattedcode/data/cyclonedx/simple/node_modules/abbrev/package.json

File renamed without changes.

tests/licensedcode/data/plugin_licenses_reference/scan.expected.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"errors": [],
1616
"extra_data": {
1717
"spdx_license_list_version": "3.16",
18-
"OUTDATED": "WARNING: Outdated ScanCode Toolkit version! You are using an outdated version of ScanCode Toolkit: 31.0.0 released on: 2021-09-24. A new version is available with important improvements including bug and security fixes, updated license, copyright and package detection, and improved scanning accuracy. Please download and install the latest version of ScanCode. Visit https://github.com/nexB/scancode-toolkit/releases for details.",
1918
"files_count": 2
2019
}
2120
}
2221
],
22+
"dependencies": [],
2323
"packages": [
2424
{
2525
"type": "npm",
@@ -49,7 +49,7 @@
4949
"homepage_url": "https://docs.npmjs.com/",
5050
"download_url": "https://registry.npmjs.org/npm/-/npm-2.13.5.tgz",
5151
"size": null,
52-
"sha1": "a124386bce4a90506f28ad4b1d1a804a17baaf32",
52+
"sha1": null,
5353
"md5": null,
5454
"sha256": null,
5555
"sha512": null,
@@ -62,11 +62,19 @@
6262
"Artistic-2.0 OR MIT"
6363
],
6464
"notice_text": null,
65-
"root_path": "scan",
65+
"root_path": null,
6666
"dependencies": [],
6767
"contains_source_code": null,
6868
"source_packages": [],
6969
"extra_data": {},
70+
"package_uuid": "pkg:npm/npm@2.13.5",
71+
"package_data_paths": [
72+
"scan/package.json"
73+
],
74+
"files": [
75+
"scan/copyr.java",
76+
"scan/package.json"
77+
],
7078
"purl": "pkg:npm/npm@2.13.5",
7179
"repository_homepage_url": "https://www.npmjs.com/package/npm",
7280
"repository_download_url": "https://registry.npmjs.org/npm/-/npm-2.13.5.tgz",
@@ -177,7 +185,8 @@
177185
"licenses": [],
178186
"license_expressions": [],
179187
"percentage_of_license_text": 0,
180-
"package_manifests": [],
188+
"package_data": [],
189+
"for_packages": [],
181190
"scan_errors": []
182191
},
183192
{
@@ -308,7 +317,10 @@
308317
"mit OR bsd-simplified"
309318
],
310319
"percentage_of_license_text": 100.0,
311-
"package_manifests": [],
320+
"package_data": [],
321+
"for_packages": [
322+
"pkg:npm/npm@2.13.5"
323+
],
312324
"scan_errors": []
313325
},
314326
{
@@ -358,7 +370,7 @@
358370
"artistic-2.0"
359371
],
360372
"percentage_of_license_text": 5.0,
361-
"package_manifests": [
373+
"package_data": [
362374
{
363375
"type": "npm",
364376
"namespace": null,
@@ -400,7 +412,7 @@
400412
"Artistic-2.0 OR MIT"
401413
],
402414
"notice_text": null,
403-
"root_path": "scan",
415+
"root_path": null,
404416
"dependencies": [],
405417
"contains_source_code": null,
406418
"source_packages": [],
@@ -411,6 +423,9 @@
411423
"api_data_url": "https://registry.npmjs.org/npm/2.13.5"
412424
}
413425
],
426+
"for_packages": [
427+
"pkg:npm/npm@2.13.5"
428+
],
414429
"scan_errors": []
415430
}
416431
]

tests/licensedcode/test_plugin_licenses_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ def test_licenses_reference_works():
2727
run_scan_click(args)
2828
check_json_scan(
2929
test_env.get_test_loc('plugin_licenses_reference/scan.expected.json'),
30-
result_file, remove_file_date=True, regen=False,
30+
result_file, remove_file_date=True, remove_instance_uuid=True, regen=False,
3131
)

0 commit comments

Comments
 (0)