Skip to content

Commit 1959835

Browse files
Support fast package-only scan in inspect_packages
Support the new only_packages attributes in scancode get_package_data API, to only scan for package data and skip license and copyright detection. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 94867ba commit 1959835

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

scanpipe/pipelines/inspect_packages.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ def scan_for_application_packages(self):
6161
# only detect package_data in resources and create
6262
# Package/Dependency instances directly instead of assembling
6363
# the packages and assigning files to them
64-
scancode.scan_for_application_packages(project=self.project, assemble=False)
64+
scancode.scan_for_application_packages(
65+
project=self.project,
66+
assemble=False,
67+
package_only=True,
68+
)
6569

6670
def create_packages_and_dependencies(self):
6771
scancode.process_package_data(self.project)

scanpipe/pipes/scancode.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from extractcode import api as extractcode_api
4040
from packagedcode import get_package_handler
4141
from packagedcode import models as packagedcode_models
42-
from packagedcode import HANDLER_BY_DATASOURCE_ID
4342
from scancode import Scanner
4443
from scancode import api as scancode_api
4544
from scancode import cli as scancode_cli
@@ -220,14 +219,18 @@ def scan_file(location, with_threading=True, min_license_score=0, **kwargs):
220219
return _scan_resource(location, scanners, with_threading=with_threading)
221220

222221

223-
def scan_for_package_data(location, with_threading=True, **kwargs):
222+
def scan_for_package_data(location, with_threading=True, package_only=False, **kwargs):
224223
"""
225224
Run a package scan on provided `location` using the scancode-toolkit direct API.
226225
227226
Return a dict of scan `results` and a list of `errors`.
228227
"""
228+
scancode_get_packages = partial(
229+
scancode_api.get_package_data,
230+
package_only=package_only,
231+
)
229232
scanners = [
230-
Scanner("package_data", scancode_api.get_package_data),
233+
Scanner("package_data", scancode_get_packages),
231234
]
232235
return _scan_resource(location, scanners, with_threading=with_threading)
233236

@@ -344,7 +347,9 @@ def scan_for_files(project, resource_qs=None, progress_logger=None):
344347
)
345348

346349

347-
def scan_for_application_packages(project, assemble=True, progress_logger=None):
350+
def scan_for_application_packages(
351+
project, assemble=True, package_only=False, progress_logger=None
352+
):
348353
"""
349354
Run a package scan on resources without a status for a `project`,
350355
and add them in their respective `package_data` attribute.
@@ -360,13 +365,18 @@ def scan_for_application_packages(project, assemble=True, progress_logger=None):
360365
"""
361366
resource_qs = project.codebaseresources.no_status()
362367

368+
scan_func_kwargs = {
369+
"package_only": package_only,
370+
}
371+
363372
# Collect detected Package data and save it to the CodebaseResource it was
364373
# detected from.
365374
scan_resources(
366375
resource_qs=resource_qs,
367376
scan_func=scan_for_package_data,
368377
save_func=save_scan_package_results,
369378
progress_logger=progress_logger,
379+
scan_func_kwargs=scan_func_kwargs,
370380
)
371381

372382
# Iterate through CodebaseResources with Package data and handle them using
@@ -469,11 +479,12 @@ def process_package_data(project):
469479

470480
package_data = pd.to_dict()
471481
dependencies = package_data.pop("dependencies")
472-
pipes.update_or_create_package(project, package_data)
473-
474482
for dep in dependencies:
475483
pipes.update_or_create_dependency(project, dep)
476484

485+
if pd.purl:
486+
pipes.update_or_create_package(project, package_data)
487+
477488

478489
def get_packages_with_purl_from_resources(project):
479490
"""

0 commit comments

Comments
 (0)