Skip to content

Commit 14d3b71

Browse files
authored
Load multiple inventories at once #451 (#452)
* Add support for multiple inputs in the LoadInventory pipeline #451 Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent ffa8d39 commit 14d3b71

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ v31.0.0 (next)
2727
Reference: https://tracker.debian.org/pkg/wait-for-it
2828
https://github.com/nexB/scancode.io/issues/387
2929

30+
- Add support for multiple inputs in the LoadInventory pipeline.
31+
https://github.com/nexB/scancode.io/issues/451
32+
3033
- Add new SCANCODEIO_REDIS_PASSWORD environment variable and setting
31-
to optionally set Redis instance password
34+
to optionally set Redis instance password.
3235

3336
- Ensure a project cannot be deleted through the API while a pipeline is running.
3437
https://github.com/nexB/scancode.io/issues/402

scanpipe/pipelines/load_inventory.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@
2626

2727
class LoadInventory(Pipeline):
2828
"""
29-
A pipeline to load an inventory of files and packages from a ScanCode JSON scan.
30-
(Presumably containing file information and package scan data).
29+
A pipeline to load one or more inventory of files and packages from a ScanCode JSON
30+
scan results. (Presumably containing resource information and package scan data).
3131
"""
3232

3333
@classmethod
3434
def steps(cls):
3535
return (
36-
cls.get_scan_json_input,
37-
cls.build_inventory_from_scan,
36+
cls.get_scan_json_inputs,
37+
cls.build_inventory_from_scans,
3838
)
3939

40-
def get_scan_json_input(self):
40+
def get_scan_json_inputs(self):
4141
"""
42-
Locates a JSON scan input from a project's input/ directory.
42+
Locates all the ScanCode JSON scan results from the project's input/ directory.
43+
This includes all files with a .json extension.
4344
"""
44-
inputs = list(self.project.inputs(pattern="*.json"))
45+
self.input_locations = [
46+
str(scan_input.absolute())
47+
for scan_input in self.project.inputs(pattern="*.json")
48+
]
4549

46-
if len(inputs) != 1:
47-
raise Exception("Only 1 JSON input file supported")
48-
49-
self.input_location = str(inputs[0].absolute())
50-
51-
def build_inventory_from_scan(self):
50+
def build_inventory_from_scans(self):
5251
"""
53-
Processes a JSON Scan results file to populate codebase resources and packages.
52+
Processes JSON scan results files to populate codebase resources and packages.
5453
"""
55-
scancode.create_inventory_from_scan(self.project, self.input_location)
54+
for input_location in self.input_locations:
55+
scancode.create_inventory_from_scan(self.project, input_location)

scanpipe/tests/data/asgiref-3.3.0_load_inventory_expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"pipeline_name": "load_inventory",
1010
"status": "not_started",
11-
"description": "A pipeline to load an inventory of files and packages from a ScanCode JSON scan.\n(Presumably containing file information and package scan data).",
11+
"description": "A pipeline to load one or more inventory of files and packages from a ScanCode JSON\nscan results. (Presumably containing resource information and package scan data).",
1212
"scancodeio_version": "",
1313
"task_id": null,
1414
"task_start_date": null,

scanpipe/tests/test_pipelines.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def test_scanpipe_pipeline_class_execute(self):
7777
run = project1.add_pipeline("do_nothing")
7878
pipeline = run.make_pipeline_instance()
7979

80-
exitcode, output = pipeline.execute()
80+
exitcode, out = pipeline.execute()
8181
self.assertEqual(0, exitcode)
82-
self.assertEqual("", output)
82+
self.assertEqual("", out)
8383

8484
run.refresh_from_db()
8585
self.assertIn("Pipeline [do_nothing] starting", run.log)
@@ -94,14 +94,14 @@ def test_scanpipe_pipeline_class_execute_with_exception(self):
9494
run = project1.add_pipeline("raise_exception")
9595
pipeline = run.make_pipeline_instance()
9696

97-
exitcode, output = pipeline.execute()
97+
exitcode, out = pipeline.execute()
9898
self.assertEqual(1, exitcode)
99-
self.assertTrue(output.startswith("Error message"))
100-
self.assertIn("Traceback:", output)
101-
self.assertIn("in execute", output)
102-
self.assertIn("step(self)", output)
103-
self.assertIn("in raise_exception", output)
104-
self.assertIn("raise ValueError", output)
99+
self.assertTrue(out.startswith("Error message"))
100+
self.assertIn("Traceback:", out)
101+
self.assertIn("in execute", out)
102+
self.assertIn("step(self)", out)
103+
self.assertIn("in raise_exception", out)
104+
self.assertIn("raise ValueError", out)
105105

106106
run.refresh_from_db()
107107
self.assertIn("Pipeline [raise_exception] starting", run.log)
@@ -145,7 +145,7 @@ def test_scanpipe_pipelines_profile_decorator(self):
145145
run = project1.add_pipeline("profile_step")
146146
pipeline_instance = run.make_pipeline_instance()
147147

148-
exitcode, output = pipeline_instance.execute()
148+
exitcode, out = pipeline_instance.execute()
149149
self.assertEqual(0, exitcode)
150150

151151
run.refresh_from_db()
@@ -296,8 +296,8 @@ def test_scanpipe_scan_package_pipeline_integration_test(self):
296296
run = project1.add_pipeline(pipeline_name)
297297
pipeline = run.make_pipeline_instance()
298298

299-
exitcode, output = pipeline.execute()
300-
self.assertEqual(0, exitcode, msg=output)
299+
exitcode, out = pipeline.execute()
300+
self.assertEqual(0, exitcode, msg=out)
301301

302302
self.assertEqual(4, project1.codebaseresources.count())
303303
self.assertEqual(1, project1.discoveredpackages.count())
@@ -329,8 +329,8 @@ def test_scanpipe_scan_package_pipeline_integration_test_multiple_packages(self)
329329
run = project1.add_pipeline(pipeline_name)
330330
pipeline = run.make_pipeline_instance()
331331

332-
exitcode, output = pipeline.execute()
333-
self.assertEqual(0, exitcode, msg=output)
332+
exitcode, out = pipeline.execute()
333+
self.assertEqual(0, exitcode, msg=out)
334334

335335
self.assertEqual(9, project1.codebaseresources.count())
336336
self.assertEqual(2, project1.discoveredpackages.count())
@@ -357,8 +357,8 @@ def test_scanpipe_scan_codebase_pipeline_integration_test(self):
357357
run = project1.add_pipeline(pipeline_name)
358358
pipeline = run.make_pipeline_instance()
359359

360-
exitcode, _ = pipeline.execute()
361-
self.assertEqual(0, exitcode)
360+
exitcode, out = pipeline.execute()
361+
self.assertEqual(0, exitcode, msg=out)
362362

363363
self.assertEqual(6, project1.codebaseresources.count())
364364
self.assertEqual(1, project1.discoveredpackages.count())
@@ -379,8 +379,8 @@ def test_scanpipe_docker_pipeline_alpine_integration_test(self):
379379
run = project1.add_pipeline(pipeline_name)
380380
pipeline = run.make_pipeline_instance()
381381

382-
exitcode, _ = pipeline.execute()
383-
self.assertEqual(0, exitcode)
382+
exitcode, out = pipeline.execute()
383+
self.assertEqual(0, exitcode, msg=out)
384384

385385
self.assertEqual(83, project1.codebaseresources.count())
386386
self.assertEqual(14, project1.discoveredpackages.count())
@@ -401,8 +401,8 @@ def test_scanpipe_docker_pipeline_rpm_integration_test(self):
401401
run = project1.add_pipeline(pipeline_name)
402402
pipeline = run.make_pipeline_instance()
403403

404-
exitcode, _ = pipeline.execute()
405-
self.assertEqual(0, exitcode)
404+
exitcode, out = pipeline.execute()
405+
self.assertEqual(0, exitcode, msg=out)
406406

407407
self.assertEqual(25, project1.codebaseresources.count())
408408
self.assertEqual(101, project1.discoveredpackages.count())
@@ -423,8 +423,8 @@ def test_scanpipe_docker_pipeline_debian_integration_test(self):
423423
run = project1.add_pipeline(pipeline_name)
424424
pipeline = run.make_pipeline_instance()
425425

426-
exitcode, _ = pipeline.execute()
427-
self.assertEqual(0, exitcode)
426+
exitcode, out = pipeline.execute()
427+
self.assertEqual(0, exitcode, msg=out)
428428

429429
self.assertEqual(6, project1.codebaseresources.count())
430430
self.assertEqual(2, project1.discoveredpackages.count())
@@ -443,8 +443,8 @@ def test_scanpipe_rootfs_pipeline_integration_test(self):
443443
run = project1.add_pipeline(pipeline_name)
444444
pipeline = run.make_pipeline_instance()
445445

446-
exitcode, _ = pipeline.execute()
447-
self.assertEqual(0, exitcode)
446+
exitcode, out = pipeline.execute()
447+
self.assertEqual(0, exitcode, msg=out)
448448

449449
self.assertEqual(6, project1.codebaseresources.count())
450450
self.assertEqual(4, project1.discoveredpackages.count())
@@ -463,8 +463,8 @@ def test_scanpipe_load_inventory_pipeline_integration_test(self):
463463
run = project1.add_pipeline(pipeline_name)
464464
pipeline = run.make_pipeline_instance()
465465

466-
exitcode, _ = pipeline.execute()
467-
self.assertEqual(0, exitcode)
466+
exitcode, out = pipeline.execute()
467+
self.assertEqual(0, exitcode, msg=out)
468468

469469
self.assertEqual(18, project1.codebaseresources.count())
470470
self.assertEqual(2, project1.discoveredpackages.count())

0 commit comments

Comments
 (0)