Count changed lines between two paths (file or directory, *.py only).
(path_a: pathlib.Path, path_b: pathlib.Path)
| 1101 | |
| 1102 | |
| 1103 | def _count_path_diff(path_a: pathlib.Path, path_b: pathlib.Path) -> int: |
| 1104 | """Count changed lines between two paths (file or directory, *.py only).""" |
| 1105 | if path_a.is_file() and path_b.is_file(): |
| 1106 | return _count_file_diff(path_a, path_b) |
| 1107 | if path_a.is_dir() and path_b.is_dir(): |
| 1108 | total = 0 |
| 1109 | a_files = {f.relative_to(path_a) for f in path_a.rglob("*.py")} |
| 1110 | b_files = {f.relative_to(path_b) for f in path_b.rglob("*.py")} |
| 1111 | for rel in a_files & b_files: |
| 1112 | total += _count_file_diff(path_a / rel, path_b / rel) |
| 1113 | for rel in a_files - b_files: |
| 1114 | content = safe_read_text(path_a / rel) |
| 1115 | if content: |
| 1116 | total += len(content.splitlines()) |
| 1117 | for rel in b_files - a_files: |
| 1118 | content = safe_read_text(path_b / rel) |
| 1119 | if content: |
| 1120 | total += len(content.splitlines()) |
| 1121 | return total |
| 1122 | return 0 |
| 1123 | |
| 1124 | |
| 1125 | @functools.cache |
no test coverage detected