(
self,
destination_path: Union[str, Path],
*,
source: Optional[str] = None,
source_file: Optional[str] = None,
)
| 152 | self.write_status("done\n") |
| 153 | |
| 154 | def _run_diff( |
| 155 | self, |
| 156 | destination_path: Union[str, Path], |
| 157 | *, |
| 158 | source: Optional[str] = None, |
| 159 | source_file: Optional[str] = None, |
| 160 | ) -> None: |
| 161 | if source_file: |
| 162 | with open(source_file, encoding="utf-8") as tf: |
| 163 | source_lines = list(tf) |
| 164 | elif source is not None: |
| 165 | source_lines = source.splitlines(keepends=True) |
| 166 | else: |
| 167 | assert False, "source or source_file is required" |
| 168 | |
| 169 | with open(destination_path, encoding="utf-8") as dp: |
| 170 | d = difflib.unified_diff( |
| 171 | list(dp), |
| 172 | source_lines, |
| 173 | fromfile=Path(destination_path).as_posix(), |
| 174 | tofile="<proposed changes>", |
| 175 | n=3, |
| 176 | lineterm="\n", |
| 177 | ) |
| 178 | d_as_list = list(d) |
| 179 | if d_as_list: |
| 180 | self.diffs_detected = True |
| 181 | print("".join(d_as_list)) |
| 182 | |
| 183 | @contextlib.contextmanager |
| 184 | def add_arguments(self) -> Iterator[ArgumentParser]: |
no test coverage detected