Skip to content

Commit 4e92a3c

Browse files
Support ignored_resources attribute in ABOUT files #809 (#810) (#810)
Reference: #809 Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 125435f commit 4e92a3c

6 files changed

Lines changed: 352 additions & 52 deletions

File tree

scanpipe/pipes/d2d.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from pathlib import Path
2525
from timeit import default_timer as timer
2626

27+
from django.db.models import Q
28+
2729
from scanpipe import pipes
2830
from scanpipe.models import CodebaseRelation
2931
from scanpipe.models import CodebaseResource
@@ -614,12 +616,23 @@ def _map_about_file_resource(project, about_file_resource, to_resources):
614616
# Cannot map anything without the about_resource value.
615617
return
616618

619+
ignored_resources = []
620+
if extra_data := package_data.get("extra_data"):
621+
ignored_resources = extra_data.get("ignored_resources")
622+
617623
# Fetch all resources that are covered by the .ABOUT file.
618624
codebase_resources = to_resources.filter(path__contains=f"/{filename.lstrip('/')}")
619625
if not codebase_resources:
620626
# If there's nothing to map on the ``to/`` do not create the package.
621627
return
622628

629+
# Ignore resources for paths in `ignored_resources` attribute
630+
if ignored_resources:
631+
lookups = Q()
632+
for resource_path in ignored_resources:
633+
lookups |= Q(**{"path__contains": resource_path})
634+
codebase_resources = codebase_resources.filter(~lookups)
635+
623636
# Create the Package using .ABOUT data and assigned related codebase_resources
624637
pipes.update_or_create_package(project, package_data, codebase_resources)
625638

scanpipe/pipes/resolve.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def resolve_about_package(input_location):
8989
if about_resource := about_data.get("about_resource"):
9090
package_data["filename"] = list(about_resource.keys())[0]
9191

92+
if ignored_resources := about_data.get("ignored_resources"):
93+
extra_data = {"ignored_resources": list(ignored_resources.keys())}
94+
package_data["extra_data"] = extra_data
95+
9296
if license_expression := about_data.get("license_expression"):
9397
package_data["declared_license_expression"] = license_expression
9498

0 commit comments

Comments
 (0)