Return a list of DependentPackage mappins from conda and pypi dependencies present in a `conda_data` mapping.
(conda_data)
| 523 | |
| 524 | |
| 525 | def get_conda_yaml_dependencies(conda_data): |
| 526 | """ |
| 527 | Return a list of DependentPackage mappins from conda and pypi |
| 528 | dependencies present in a `conda_data` mapping. |
| 529 | """ |
| 530 | dependencies = conda_data.get('dependencies') or [] |
| 531 | deps = [] |
| 532 | for dep in dependencies: |
| 533 | if isinstance(dep, str): |
| 534 | namespace = None |
| 535 | specs = None |
| 536 | is_pinned = False |
| 537 | |
| 538 | if "::" in dep: |
| 539 | namespace, dep = dep.split("::") |
| 540 | if "/" in namespace or ":" in namespace: |
| 541 | namespace = None |
| 542 | |
| 543 | req = parse_requirement_line(dep) |
| 544 | if req: |
| 545 | name = req.name |
| 546 | version = None |
| 547 | |
| 548 | specs = str(req.specs) |
| 549 | if '==' in specs: |
| 550 | version = specs.replace('==','') |
| 551 | is_pinned = True |
| 552 | purl = PackageURL(type='pypi', name=name, version=version) |
| 553 | else: |
| 554 | if "=" in dep: |
| 555 | dep, version = dep.split("=") |
| 556 | is_pinned = True |
| 557 | specs = f"={version}" |
| 558 | |
| 559 | purl = PackageURL( |
| 560 | type='conda', |
| 561 | namespace=namespace, |
| 562 | name=dep, |
| 563 | version=version, |
| 564 | ) |
| 565 | |
| 566 | if purl.name in ('pip', 'python'): |
| 567 | continue |
| 568 | |
| 569 | deps.append( |
| 570 | models.DependentPackage( |
| 571 | purl=purl.to_string(), |
| 572 | extracted_requirement=specs, |
| 573 | scope='dependencies', |
| 574 | is_runtime=True, |
| 575 | is_optional=False, |
| 576 | is_pinned=is_pinned, |
| 577 | is_direct=True, |
| 578 | ).to_dict() |
| 579 | ) |
| 580 | |
| 581 | elif isinstance(dep, dict): |
| 582 | for line in dep.get('pip', []): |