Skip to content

Commit 05ee44d

Browse files
committed
fix scan_single_package not giving corect parent_path
Signed-off-by: Aayush Kumar <[email protected]>
1 parent 2b5b2f7 commit 05ee44d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

scanpipe/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ class CodebaseResource(
27012701
blank=True,
27022702
help_text=_(
27032703
"The path of the resource's parent directory. "
2704-
"Set to None for top-level (root) resources. "
2704+
"Set to empty string for top-level (root) resources. "
27052705
"Used to efficiently retrieve a directory's contents."
27062706
),
27072707
)

scanpipe/pipes/scancode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ def create_codebase_resources(project, scanned_codebase):
818818
# includes the "root". The `get_path` method is used instead.
819819
if field.name == "path":
820820
continue
821+
if field.name == "parent_path":
822+
continue
821823
value = getattr(scanned_resource, field.name, None)
822824
if value is not None:
823825
resource_data[field.name] = value
@@ -826,6 +828,11 @@ def create_codebase_resources(project, scanned_codebase):
826828
resource_data["type"] = CodebaseResource.Type[resource_type]
827829
resource_path = scanned_resource.get_path(strip_root=True)
828830

831+
parent_path = str(Path(resource_path).parent)
832+
if parent_path == ".":
833+
parent_path = ""
834+
resource_data["parent_path"] = parent_path
835+
829836
codebase_resource, _ = CodebaseResource.objects.get_or_create(
830837
project=project,
831838
path=resource_path,

scanpipe/tests/pipes/test_scancode.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,21 @@ def test_scanpipe_scancode_resolve_dependencies_no_requirements(self):
723723
resolved_dep = project1.discovereddependencies.get(name="bluebird")
724724
self.assertEqual(resolved_dep, dep_2)
725725
self.assertEqual(resolved_dep.resolved_to_package, pkg_1)
726+
727+
def test_scanpipe_pipes_scancode_scan_single_package_correct_parent_path(self):
728+
project1 = Project.objects.create(name="Analysis")
729+
input_location = self.data / "scancode" / "is-npm-1.0.0.tgz"
730+
project1.copy_input_from(input_location)
731+
run = project1.add_pipeline("scan_single_package")
732+
pipeline = run.make_pipeline_instance()
733+
exitcode, out = pipeline.execute()
734+
735+
self.assertEqual(0, exitcode, msg=out)
736+
self.assertEqual(4, project1.codebaseresources.count())
737+
738+
root = project1.codebaseresources.get(path="package")
739+
self.assertEqual("", root.parent_path)
740+
self.assertNotEqual("codebase", root.parent_path)
741+
742+
file1 = project1.codebaseresources.get(path="package/index.js")
743+
self.assertEqual("package", file1.parent_path)

0 commit comments

Comments
 (0)