|
31 | 31 | from packageurl import PackageURL
|
32 | 32 | from univers.version_range import RANGE_CLASS_BY_SCHEMES
|
33 | 33 | from univers.version_range import InvalidVersionRange
|
| 34 | +from univers.versions import InvalidVersion |
34 | 35 |
|
35 | 36 | from aboutcode.pipeline import LoopProgress
|
36 | 37 | from scanpipe.pipes import _clean_package_data
|
@@ -300,28 +301,43 @@ def get_unique_resolved_purls(project):
|
300 | 301 | def get_unique_unresolved_purls(project):
|
301 | 302 | """Return PURLs from project's unresolved DiscoveredDependencies."""
|
302 | 303 | packages_unresolved = project.discovereddependencies.filter(
|
303 |
| - is_pinned=False |
| 304 | + is_pinned=False, |
304 | 305 | ).exclude(extracted_requirement="*")
|
305 | 306 |
|
306 |
| - distinct_unresolved_results = packages_unresolved.values( |
| 307 | + distinct_unpinned_results = packages_unresolved.values( |
307 | 308 | "type", "namespace", "name", "extracted_requirement"
|
308 | 309 | )
|
309 | 310 |
|
310 |
| - distinct_unresolved = {tuple(item.values()) for item in distinct_unresolved_results} |
| 311 | + distinct_unpinned = {tuple(item.values()) for item in distinct_unpinned_results} |
311 | 312 |
|
312 | 313 | packages = set()
|
313 |
| - for item in distinct_unresolved: |
| 314 | + for item in distinct_unpinned: |
314 | 315 | pkg_type, namespace, name, extracted_requirement = item
|
315 | 316 | if range_class := RANGE_CLASS_BY_SCHEMES.get(pkg_type):
|
| 317 | + purl = PackageURL(type=pkg_type, namespace=namespace, name=name) |
| 318 | + |
316 | 319 | try:
|
317 | 320 | vers = range_class.from_native(extracted_requirement)
|
318 |
| - except InvalidVersionRange: |
| 321 | + except (InvalidVersionRange, InvalidVersion) as exception: |
| 322 | + if exception is InvalidVersionRange: |
| 323 | + description = "Version range is invalid or unsupported" |
| 324 | + else: |
| 325 | + description = "Extracted requirement is not a valid version" |
| 326 | + details = { |
| 327 | + "purl": purl, |
| 328 | + "extracted_requirement": extracted_requirement, |
| 329 | + } |
| 330 | + project.add_error( |
| 331 | + description=description, |
| 332 | + model="get_unique_unresolved_purls", |
| 333 | + details=details, |
| 334 | + exception=exception, |
| 335 | + ) |
319 | 336 | continue
|
320 | 337 |
|
321 | 338 | if not vers.constraints:
|
322 | 339 | continue
|
323 | 340 |
|
324 |
| - purl = PackageURL(type=pkg_type, namespace=namespace, name=name) |
325 | 341 | packages.add((str(purl), str(vers)))
|
326 | 342 |
|
327 | 343 | return packages
|
|
0 commit comments