Internal function to extract metainfo from a package. Currently supported info types: - name - dependencies (a list of dependencies)
(dependency,
extract_type=None,
debug=False,
include_build_requirements=False
)
| 498 | |
| 499 | |
| 500 | def _extract_info_from_package(dependency, |
| 501 | extract_type=None, |
| 502 | debug=False, |
| 503 | include_build_requirements=False |
| 504 | ): |
| 505 | """ Internal function to extract metainfo from a package. |
| 506 | Currently supported info types: |
| 507 | |
| 508 | - name |
| 509 | - dependencies (a list of dependencies) |
| 510 | """ |
| 511 | if debug: |
| 512 | print("_extract_info_from_package called with " |
| 513 | "extract_type={} include_build_requirements={}".format( |
| 514 | extract_type, include_build_requirements, |
| 515 | )) |
| 516 | output_folder = tempfile.mkdtemp(prefix="pythonpackage-metafolder-") |
| 517 | try: |
| 518 | extract_metainfo_files_from_package( |
| 519 | dependency, output_folder, debug=debug |
| 520 | ) |
| 521 | |
| 522 | # Extract the type of data source we used to get the metadata: |
| 523 | with open(os.path.join(output_folder, |
| 524 | "metadata_source"), "r") as f: |
| 525 | metadata_source_type = f.read().strip() |
| 526 | |
| 527 | # Extract main METADATA file: |
| 528 | with open(os.path.join(output_folder, "METADATA"), |
| 529 | "r", encoding="utf-8" |
| 530 | ) as f: |
| 531 | # Get metadata and cut away description (is after 2 linebreaks) |
| 532 | metadata_entries = f.read().partition("\n\n")[0].splitlines() |
| 533 | |
| 534 | if extract_type == "name": |
| 535 | name = None |
| 536 | for meta_entry in metadata_entries: |
| 537 | if meta_entry.lower().startswith("name:"): |
| 538 | return meta_entry.partition(":")[2].strip() |
| 539 | if name is None: |
| 540 | raise ValueError("failed to obtain package name") |
| 541 | return name |
| 542 | elif extract_type == "dependencies": |
| 543 | # First, make sure we don't attempt to return build requirements |
| 544 | # for wheels since they usually come without pyproject.toml |
| 545 | # and we haven't implemented another way to get them: |
| 546 | if include_build_requirements and \ |
| 547 | metadata_source_type == "wheel": |
| 548 | if debug: |
| 549 | print("_extract_info_from_package: was called " |
| 550 | "with include_build_requirements=True on " |
| 551 | "package obtained as wheel, raising error...") |
| 552 | raise NotImplementedError( |
| 553 | "fetching build requirements for " |
| 554 | "wheels is not implemented" |
| 555 | ) |
| 556 | |
| 557 | # Get build requirements from pyproject.toml if requested: |