MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_package_and_deps

Function get_package_and_deps

src/packagedcode/plugin_package.py:408–491  ·  view source on GitHub ↗

Return a tuple of (Packages list, Dependency list) from the parsed package data present in the codebase files.package_data attributes.

(codebase, package_adder=add_to_package, strip_root=False, **kwargs)

Source from the content-addressed store, hash-verified

406
407
408def get_package_and_deps(codebase, package_adder=add_to_package, strip_root=False, **kwargs):
409 """
410 Return a tuple of (Packages list, Dependency list) from the parsed package
411 data present in the codebase files.package_data attributes.
412 """
413 packages = []
414 dependencies = []
415
416 seen_resource_paths = set()
417
418 has_single_resource = codebase.has_single_resource
419 # track resource ids that have been already processed
420 for resource in codebase.walk(topdown=False):
421 if not resource.package_data:
422 continue
423
424 if resource.path in seen_resource_paths:
425 continue
426
427 if TRACE_ASSEMBLY:
428 logger_debug('get_package_and_deps: location:', resource.location)
429
430 for package_data in resource.package_data:
431 try:
432 package_data = PackageData.from_dict(mapping=package_data)
433
434 if TRACE_ASSEMBLY:
435 logger_debug(' get_package_and_deps: package_data:', package_data)
436
437 # Find a handler for this package datasource to assemble collect
438 # packages and deps
439 handler = get_package_handler(package_data)
440 if TRACE_ASSEMBLY:
441 logger_debug(' get_package_and_deps: handler:', handler)
442
443 items = handler.assemble(
444 package_data=package_data,
445 resource=resource,
446 codebase=codebase,
447 package_adder=package_adder,
448 )
449
450 for item in items:
451 if TRACE_ASSEMBLY:
452 logger_debug(' get_package_and_deps: item:', item)
453
454 if isinstance(item, Package):
455 if strip_root and not has_single_resource:
456 item.datafile_paths = [
457 strip_first_path_segment(dfp)
458 for dfp in item.datafile_paths
459 ]
460 packages.append(item)
461 if TRACE:
462 logger_debug(' get_package_and_deps: Package:', item.purl)
463
464 elif isinstance(item, Dependency):
465 if strip_root and not has_single_resource:

Callers 2

create_package_and_depsFunction · 0.85

Calls 9

get_package_handlerFunction · 0.90
strip_first_path_segmentFunction · 0.90
addMethod · 0.80
logger_debugFunction · 0.70
walkMethod · 0.45
from_dictMethod · 0.45
assembleMethod · 0.45
appendMethod · 0.45
saveMethod · 0.45

Tested by 1