(codebase)
| 169 | |
| 170 | |
| 171 | def get_ambiguous_package_detections(codebase): |
| 172 | codebase_packages = codebase.attributes.packages |
| 173 | codebase_dependencies = codebase.attributes.dependencies |
| 174 | |
| 175 | codebase_packages_purls = [ |
| 176 | package["purl"] |
| 177 | for package in codebase_packages |
| 178 | ] |
| 179 | deps_datafile_paths = set() |
| 180 | deps_datafile_paths.update([ |
| 181 | dep["datafile_path"] |
| 182 | for dep in codebase_dependencies |
| 183 | ]) |
| 184 | |
| 185 | ambi_package_detections = [] |
| 186 | |
| 187 | for resource in codebase.walk(): |
| 188 | package_data = getattr(resource, 'package_data', []) or [] |
| 189 | for package in package_data: |
| 190 | detection_type = None |
| 191 | |
| 192 | # Top-level packages are not created for private packages so |
| 193 | # these should not be consider for package detection issues |
| 194 | is_private = package.get("is_private", False) |
| 195 | if is_private: |
| 196 | continue |
| 197 | |
| 198 | if not package["purl"]: |
| 199 | if resource.path not in deps_datafile_paths and not resource.for_packages: |
| 200 | detection_type=PackageDetectionCategory.CANNOT_CREATE_PURL.value |
| 201 | else: |
| 202 | if package["purl"] not in codebase_packages_purls: |
| 203 | detection_type=PackageDetectionCategory.CANNOT_CREATE_TOP_LEVEL_PACKAGE.value |
| 204 | |
| 205 | if detection_type: |
| 206 | ambi_package_detections.append( |
| 207 | AmbiguousDetection.from_package( |
| 208 | package_data=package, |
| 209 | detection_log=[detection_type], |
| 210 | file_path=resource.path, |
| 211 | ) |
| 212 | ) |
| 213 | |
| 214 | return ambi_package_detections |
| 215 | |
| 216 | |
| 217 | def populate_resources_for_reviews(codebase, ambiguous_detections): |
no test coverage detected