|
3 | 3 |
|
4 | 4 | __all__ = ("filesToTag", "DoxygenBuilder") |
5 | 5 |
|
| 6 | +import csv |
6 | 7 | import fnmatch |
7 | 8 | import os |
8 | 9 | import re |
@@ -739,6 +740,43 @@ def makeEntryPoints(target, source, env): |
739 | 740 | self.Command(filename, [], self.Action(makeEntryPoints, strfunction=lambda *args: None)) |
740 | 741 | ) |
741 | 742 |
|
| 743 | + def makeRecordFile(target, source, env): |
| 744 | + # Write the RECORD file containing every python file in the package. |
| 745 | + # Do not attempt to write hashes and file sizes since these can |
| 746 | + # change if the package is not really installed into an EUPS tree. |
| 747 | + all_files = set() |
| 748 | + for root, dirs, files in os.walk(pythonDir): |
| 749 | + root = root.removeprefix(pythonDir) |
| 750 | + root = root.removeprefix("/") |
| 751 | + all_files.update({os.path.join(root, f) for f in files}) |
| 752 | + # Ensure that RECORD itself is included in the list. |
| 753 | + record_path = target[0].abspath |
| 754 | + record_path = record_path.removeprefix(os.path.abspath(pythonDir)).removeprefix("/") |
| 755 | + all_files.add(record_path) |
| 756 | + |
| 757 | + # Also force the other metadata files we are writing into the |
| 758 | + # file in case the order cannot be guaranteed. |
| 759 | + meta_files = ["INSTALLER", "METADATA"] |
| 760 | + if entryPoints: |
| 761 | + meta_files.append("entry_points.txt") |
| 762 | + dist_path, _ = os.path.split(record_path) |
| 763 | + for f in meta_files: |
| 764 | + all_files.add(os.path.join(dist_path, f)) |
| 765 | + |
| 766 | + # The RECORD file is nominally a CSV file. |
| 767 | + # Do not record file sizes or hashes. |
| 768 | + rows = [(f, "", "") for f in sorted(all_files)] |
| 769 | + with open(target[0].abspath, "w") as outFile: |
| 770 | + csv_writer = csv.writer(outFile) |
| 771 | + csv_writer.writerows(rows) |
| 772 | + |
| 773 | + filename = os.path.join(distDir, "RECORD") |
| 774 | + # This action really needs to run after the previous pkginfo actions |
| 775 | + # so that INSTALLER, entry_points.txt and METADATA files are created. |
| 776 | + # Additionally, the RECORD target needs to run after "python" so that |
| 777 | + # shared libraries are created -- this is configured elsewhere. |
| 778 | + results.append(self.Command(filename, [], self.Action(makeRecordFile, strfunction=lambda *args: None))) |
| 779 | + |
742 | 780 | self.AlwaysBuild(results) |
743 | 781 | return results |
744 | 782 |
|
|
0 commit comments