Check if two file paths match using multiple strategies
(
normalized_target: str,
normalized_summary: str,
original_target: str,
original_summary: str,
)
| 1053 | |
| 1054 | |
| 1055 | def _paths_match( |
| 1056 | normalized_target: str, |
| 1057 | normalized_summary: str, |
| 1058 | original_target: str, |
| 1059 | original_summary: str, |
| 1060 | ) -> bool: |
| 1061 | """Check if two file paths match using multiple strategies""" |
| 1062 | |
| 1063 | # Strategy 1: Exact normalized match |
| 1064 | if normalized_target == normalized_summary: |
| 1065 | return True |
| 1066 | |
| 1067 | # Strategy 2: Basename match (filename only) |
| 1068 | target_basename = os.path.basename(original_target) |
| 1069 | summary_basename = os.path.basename(original_summary) |
| 1070 | if target_basename == summary_basename and len(target_basename) > 4: |
| 1071 | return True |
| 1072 | |
| 1073 | # Strategy 3: Suffix match (remove common prefixes and compare) |
| 1074 | target_suffix = _remove_common_prefixes(normalized_target) |
| 1075 | summary_suffix = _remove_common_prefixes(normalized_summary) |
| 1076 | if target_suffix == summary_suffix: |
| 1077 | return True |
| 1078 | |
| 1079 | # Strategy 4: Ends with match |
| 1080 | if normalized_target.endswith(normalized_summary) or normalized_summary.endswith( |
| 1081 | normalized_target |
| 1082 | ): |
| 1083 | return True |
| 1084 | |
| 1085 | # Strategy 5: Contains match for longer paths |
| 1086 | if len(normalized_target) > 10 and normalized_target in normalized_summary: |
| 1087 | return True |
| 1088 | if len(normalized_summary) > 10 and normalized_summary in normalized_target: |
| 1089 | return True |
| 1090 | |
| 1091 | return False |
| 1092 | |
| 1093 | |
| 1094 | def _remove_common_prefixes(file_path: str) -> str: |
no test coverage detected