Files in this distribution. :return: List of PackagePath for this distribution or None Result is `None` if the metadata file that enumerates files (i.e. RECORD for dist-info, or installed-files.txt or SOURCES.txt for egg-info) is missing. Result may be empty
(self)
| 582 | |
| 583 | @property |
| 584 | def files(self) -> list[PackagePath] | None: |
| 585 | """Files in this distribution. |
| 586 | |
| 587 | :return: List of PackagePath for this distribution or None |
| 588 | |
| 589 | Result is `None` if the metadata file that enumerates files |
| 590 | (i.e. RECORD for dist-info, or installed-files.txt or |
| 591 | SOURCES.txt for egg-info) is missing. |
| 592 | Result may be empty if the metadata exists but is empty. |
| 593 | |
| 594 | Custom providers are recommended to provide a "RECORD" file (in |
| 595 | ``read_text``) or override this property to allow for callers to be |
| 596 | able to resolve filenames provided by the package. |
| 597 | """ |
| 598 | |
| 599 | def make_file(name, hash=None, size_str=None): |
| 600 | result = PackagePath(name) |
| 601 | result.hash = FileHash(hash) if hash else None |
| 602 | result.size = int(size_str) if size_str else None |
| 603 | result.dist = self |
| 604 | return result |
| 605 | |
| 606 | @pass_none |
| 607 | def make_files(lines): |
| 608 | # Delay csv import, since Distribution.files is not as widely used |
| 609 | # as other parts of importlib.metadata |
| 610 | import csv |
| 611 | |
| 612 | return starmap(make_file, csv.reader(lines)) |
| 613 | |
| 614 | @pass_none |
| 615 | def skip_missing_files(package_paths): |
| 616 | return list(filter(lambda path: path.locate().exists(), package_paths)) |
| 617 | |
| 618 | return skip_missing_files( |
| 619 | make_files( |
| 620 | self._read_files_distinfo() |
| 621 | or self._read_files_egginfo_installed() |
| 622 | or self._read_files_egginfo_sources() |
| 623 | ) |
| 624 | ) |
| 625 | |
| 626 | def _read_files_distinfo(self): |
| 627 | """ |
nothing calls this directly
no test coverage detected