(self, edits)
| 67 | return edits |
| 68 | |
| 69 | def apply_edits(self, edits): |
| 70 | seen = set() |
| 71 | uniq = [] |
| 72 | for path, hunk in edits: |
| 73 | hunk = normalize_hunk(hunk) |
| 74 | if not hunk: |
| 75 | continue |
| 76 | |
| 77 | this = [path + "\n"] + hunk |
| 78 | this = "".join(this) |
| 79 | |
| 80 | if this in seen: |
| 81 | continue |
| 82 | seen.add(this) |
| 83 | |
| 84 | uniq.append((path, hunk)) |
| 85 | |
| 86 | errors = [] |
| 87 | for path, hunk in uniq: |
| 88 | full_path = self.abs_root_path(path) |
| 89 | content = self.io.read_text(full_path) |
| 90 | |
| 91 | original, _ = hunk_to_before_after(hunk) |
| 92 | |
| 93 | try: |
| 94 | content = do_replace(full_path, content, hunk) |
| 95 | except SearchTextNotUnique: |
| 96 | errors.append( |
| 97 | not_unique_error.format( |
| 98 | path=path, original=original, num_lines=len(original.splitlines()) |
| 99 | ) |
| 100 | ) |
| 101 | continue |
| 102 | |
| 103 | if not content: |
| 104 | errors.append( |
| 105 | no_match_error.format( |
| 106 | path=path, original=original, num_lines=len(original.splitlines()) |
| 107 | ) |
| 108 | ) |
| 109 | continue |
| 110 | |
| 111 | # SUCCESS! |
| 112 | self.io.write_text(full_path, content) |
| 113 | |
| 114 | if errors: |
| 115 | errors = "\n\n".join(errors) |
| 116 | if len(errors) < len(uniq): |
| 117 | errors += other_hunks_applied |
| 118 | raise ValueError(errors) |
| 119 | |
| 120 | |
| 121 | def do_replace(fname, content, hunk): |
nothing calls this directly
no test coverage detected