@@ -50,7 +50,9 @@ class PackageScanner(ScanPlugin):
5050 """
5151
5252 resource_attributes = {}
53- resource_attributes ['packages' ] = attr .ib (default = attr .Factory (list ), repr = False )
53+ codebase_attributes = {}
54+ resource_attributes ['package_manifests' ] = attr .ib (default = attr .Factory (list ), repr = False )
55+ codebase_attributes ['packages' ] = attr .ib (default = attr .Factory (list ), repr = False )
5456
5557 sort_order = 6
5658
@@ -78,13 +80,15 @@ def get_scanner(self, **kwargs):
7880 """
7981 Return a scanner callable to scan a Resource for packages.
8082 """
81- from scancode .api import get_package_info
82- return get_package_info
83+ from scancode .api import get_package_manifests
84+ return get_package_manifests
8385
8486 def process_codebase (self , codebase , ** kwargs ):
8587 """
8688 Set the package root given a package "type".
8789 """
90+ create_packages_from_manifests (codebase , ** kwargs )
91+
8892 if codebase .has_single_resource :
8993 # What if we scanned a single file and we do not have a root proper?
9094 return
@@ -93,6 +97,19 @@ def process_codebase(self, codebase, **kwargs):
9397 set_packages_root (resource , codebase )
9498
9599
100+ def create_packages_from_manifests (codebase , ** kwargs ):
101+ """
102+ Create package instances from package manifests present in the codebase.
103+ """
104+ package_manifests = []
105+
106+ for resource in codebase .walk (topdown = False ):
107+ if resource .package_manifests :
108+ package_manifests .extend (resource .package_manifests )
109+
110+ codebase .attributes .packages .extend (package_manifests )
111+
112+
96113def set_packages_root (resource , codebase ):
97114 """
98115 Set the root_path attribute as the path to the root Resource for a given
@@ -102,25 +119,25 @@ def set_packages_root(resource, codebase):
102119 if not resource .is_file :
103120 return
104121
105- packages = resource .packages
106- if not packages :
122+ package_manifests = resource .package_manifests
123+ if not package_manifests :
107124 return
108125 # NOTE: we are dealing with a single file therefore there should be only be
109126 # a single package detected. But some package manifests can document more
110127 # than one package at a time such as multiple arches/platforms for a gempsec
111128 # or multiple sub package (with "%package") in an RPM .spec file.
112129
113130 modified = False
114- for package in packages :
115- package_instance = get_package_instance (package )
131+ for package_manifest in package_manifests :
132+ package_instance = get_package_instance (package_manifest )
116133 package_root = package_instance .get_package_root (resource , codebase )
117134 if not package_root :
118135 # this can happen if we scan a single resource that is a package package
119136 continue
120137 # What if the target resource (e.g. a parent) is the root and we are in stripped root mode?
121138 if package_root .is_root and codebase .strip_root :
122139 continue
123- package ['root_path' ] = package_root .path
140+ package_manifest ['root_path' ] = package_root .path
124141 modified = True
125142
126143 if modified :
0 commit comments