Add licenses keys to a ``extensions`` entry for JSON distribution info.
(entry)
| 529 | |
| 530 | |
| 531 | def add_licenses_to_extension_entry(entry): |
| 532 | """Add licenses keys to a ``extensions`` entry for JSON distribution info.""" |
| 533 | |
| 534 | have_licenses = False |
| 535 | licenses = set() |
| 536 | license_paths = set() |
| 537 | license_public_domain = None |
| 538 | |
| 539 | have_local_link = False |
| 540 | |
| 541 | for link in entry["links"]: |
| 542 | name = link["name"] |
| 543 | if "path_static" in link or "path_dynamic" in link: |
| 544 | have_local_link = True |
| 545 | |
| 546 | for value in DOWNLOADS.values(): |
| 547 | if name not in value.get("library_names", []): |
| 548 | continue |
| 549 | |
| 550 | # Don't add licenses annotations if they aren't defined. This leaves |
| 551 | # things as "unknown" to consumers. |
| 552 | if "licenses" not in value: |
| 553 | continue |
| 554 | |
| 555 | have_licenses = True |
| 556 | licenses |= set(value["licenses"]) |
| 557 | license_paths.add("licenses/%s" % value["license_file"]) |
| 558 | license_public_domain = value.get("license_public_domain", False) |
| 559 | |
| 560 | if have_local_link and not have_licenses: |
| 561 | raise Exception( |
| 562 | "missing license for local library for extension entry: %s" % entry |
| 563 | ) |
| 564 | |
| 565 | if not have_licenses: |
| 566 | return |
| 567 | |
| 568 | entry["licenses"] = sorted(licenses) |
| 569 | entry["license_paths"] = sorted(license_paths) |
| 570 | entry["license_public_domain"] = license_public_domain |
| 571 | |
| 572 | |
| 573 | def add_env_common(env): |