Print the content of a source file.
(self, args, screen_info=None)
| 1109 | parsed.max_elements_per_line + max_elements_per_line_increase) |
| 1110 | |
| 1111 | def print_source(self, args, screen_info=None): |
| 1112 | """Print the content of a source file.""" |
| 1113 | del screen_info # Unused. |
| 1114 | |
| 1115 | parsed = self._arg_parsers["print_source"].parse_args(args) |
| 1116 | |
| 1117 | source_annotation = source_utils.annotate_source( |
| 1118 | self._debug_dump, |
| 1119 | parsed.source_file_path, |
| 1120 | do_dumped_tensors=parsed.tensors) |
| 1121 | |
| 1122 | source_lines, line_num_width = source_utils.load_source( |
| 1123 | parsed.source_file_path) |
| 1124 | |
| 1125 | labeled_source_lines = [] |
| 1126 | actual_initial_scroll_target = 0 |
| 1127 | for i, line in enumerate(source_lines): |
| 1128 | annotated_line = RL("L%d" % (i + 1), cli_shared.COLOR_YELLOW) |
| 1129 | annotated_line += " " * (line_num_width - len(annotated_line)) |
| 1130 | annotated_line += line |
| 1131 | labeled_source_lines.append(annotated_line) |
| 1132 | |
| 1133 | if i + 1 == parsed.line_begin: |
| 1134 | actual_initial_scroll_target = len(labeled_source_lines) - 1 |
| 1135 | |
| 1136 | if i + 1 in source_annotation: |
| 1137 | sorted_elements = sorted(source_annotation[i + 1]) |
| 1138 | for k, element in enumerate(sorted_elements): |
| 1139 | if k >= parsed.max_elements_per_line: |
| 1140 | omitted_info_line = RL(" (... Omitted %d of %d %s ...) " % ( |
| 1141 | len(sorted_elements) - parsed.max_elements_per_line, |
| 1142 | len(sorted_elements), |
| 1143 | "tensor(s)" if parsed.tensors else "op(s)")) |
| 1144 | omitted_info_line += RL( |
| 1145 | "+5", |
| 1146 | debugger_cli_common.MenuItem( |
| 1147 | None, |
| 1148 | self._reconstruct_print_source_command( |
| 1149 | parsed, i + 1, max_elements_per_line_increase=5))) |
| 1150 | labeled_source_lines.append(omitted_info_line) |
| 1151 | break |
| 1152 | |
| 1153 | label = RL(" " * 4) |
| 1154 | if self._debug_dump.debug_watch_keys( |
| 1155 | debug_graphs.get_node_name(element)): |
| 1156 | attribute = debugger_cli_common.MenuItem("", "pt %s" % element) |
| 1157 | else: |
| 1158 | attribute = cli_shared.COLOR_BLUE |
| 1159 | |
| 1160 | label += RL(element, attribute) |
| 1161 | labeled_source_lines.append(label) |
| 1162 | |
| 1163 | output = debugger_cli_common.rich_text_lines_from_rich_line_list( |
| 1164 | labeled_source_lines, |
| 1165 | annotations={debugger_cli_common.INIT_SCROLL_POS_KEY: |
| 1166 | actual_initial_scroll_target}) |
| 1167 | _add_main_menu(output, node_name=None) |
| 1168 | return output |