| 895 | self.files.append(file_info) |
| 896 | |
| 897 | def on_finish(self) -> None: |
| 898 | if not self.files: |
| 899 | # Nothing to do. |
| 900 | return |
| 901 | output_files = sorted(self.files, key=lambda x: x.module) |
| 902 | report_file = os.path.join(self.output_dir, "lineprecision.txt") |
| 903 | width = max(4, max(len(info.module) for info in output_files)) |
| 904 | titles = ("Lines", "Precise", "Imprecise", "Any", "Empty", "Unanalyzed") |
| 905 | widths = (width,) + tuple(len(t) for t in titles) |
| 906 | fmt = "{:%d} {:%d} {:%d} {:%d} {:%d} {:%d} {:%d}\n" % widths |
| 907 | with open(report_file, "w") as f: |
| 908 | f.write(fmt.format("Name", *titles)) |
| 909 | f.write("-" * (width + 51) + "\n") |
| 910 | for file_info in output_files: |
| 911 | counts = file_info.counts |
| 912 | f.write( |
| 913 | fmt.format( |
| 914 | file_info.module.ljust(width), |
| 915 | file_info.total(), |
| 916 | counts[stats.TYPE_PRECISE], |
| 917 | counts[stats.TYPE_IMPRECISE], |
| 918 | counts[stats.TYPE_ANY], |
| 919 | counts[stats.TYPE_EMPTY], |
| 920 | counts[stats.TYPE_UNANALYZED], |
| 921 | ) |
| 922 | ) |
| 923 | |
| 924 | |
| 925 | register_reporter("lineprecision", LinePrecisionReporter) |