Alternative method to extract file section using simpler pattern matching
(
summary_content: str, target_file_path: str
)
| 1104 | |
| 1105 | |
| 1106 | def _extract_file_section_alternative( |
| 1107 | summary_content: str, target_file_path: str |
| 1108 | ) -> str: |
| 1109 | """Alternative method to extract file section using simpler pattern matching""" |
| 1110 | |
| 1111 | # Get the basename for fallback matching |
| 1112 | target_basename = os.path.basename(target_file_path) |
| 1113 | |
| 1114 | # Split by separator lines to get individual sections |
| 1115 | sections = summary_content.split("=" * 80) |
| 1116 | |
| 1117 | for i, section in enumerate(sections): |
| 1118 | if "## IMPLEMENTATION File" in section: |
| 1119 | # Extract the file path from the header |
| 1120 | lines = section.strip().split("\n") |
| 1121 | for line in lines: |
| 1122 | if "## IMPLEMENTATION File" in line: |
| 1123 | # Extract file path between "File " and "; ROUND" |
| 1124 | try: |
| 1125 | file_part = line.split("File ")[1].split("; ROUND")[0].strip() |
| 1126 | |
| 1127 | # Check if this matches our target |
| 1128 | if ( |
| 1129 | _normalize_file_path(target_file_path) |
| 1130 | == _normalize_file_path(file_part) |
| 1131 | or target_basename == os.path.basename(file_part) |
| 1132 | or target_file_path in file_part |
| 1133 | or file_part.endswith(target_file_path) |
| 1134 | ): |
| 1135 | # Get the next section which contains the content |
| 1136 | if i + 1 < len(sections): |
| 1137 | content_section = sections[i + 1].strip() |
| 1138 | return f"""================================================================================ |
| 1139 | ## IMPLEMENTATION File {file_part} |
| 1140 | ================================================================================ |
| 1141 | |
| 1142 | {content_section} |
| 1143 | |
| 1144 | --- |
| 1145 | *Extracted from implement_code_summary.md using alternative method*""" |
| 1146 | except (IndexError, AttributeError): |
| 1147 | continue |
| 1148 | |
| 1149 | return None |
| 1150 | |
| 1151 | |
| 1152 | # ==================== Code Search Tools ==================== |
no test coverage detected