Write file if content changed. Returns True if written.
(self, rel_path: str, content: str)
| 1233 | self.skipped: List[str] = [] |
| 1234 | |
| 1235 | def write(self, rel_path: str, content: str) -> bool: |
| 1236 | """Write file if content changed. Returns True if written.""" |
| 1237 | full_path = self.output_dir / rel_path |
| 1238 | if self.dry_run: |
| 1239 | print(f" [DRY-RUN] Would write: {rel_path} ({len(content):,} bytes)") |
| 1240 | self.written.append(rel_path) |
| 1241 | return True |
| 1242 | |
| 1243 | full_path.parent.mkdir(parents=True, exist_ok=True) |
| 1244 | |
| 1245 | # Skip if content unchanged |
| 1246 | if full_path.exists(): |
| 1247 | existing = full_path.read_text(encoding="utf-8") |
| 1248 | if existing == content: |
| 1249 | self.skipped.append(rel_path) |
| 1250 | return False |
| 1251 | |
| 1252 | full_path.write_text(content, encoding="utf-8") |
| 1253 | self.written.append(rel_path) |
| 1254 | return True |
| 1255 | |
| 1256 | def ensure_init_files(self, all_module_paths: List[str]) -> None: |
| 1257 | """Ensure every package directory has an __init__.py.""" |
no outgoing calls
no test coverage detected