MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _run_diff

Method _run_diff

lib/sqlalchemy/util/tool_support.py:154–181  ·  view source on GitHub ↗
(
        self,
        destination_path: Union[str, Path],
        *,
        source: Optional[str] = None,
        source_file: Optional[str] = None,
    )

Source from the content-addressed store, hash-verified

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]:

Calls 2

openFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected