from pathlib import Path path = Path("ProviderCore/registry.py") text = path.read_text() marker = '"""Provider registry.' first = text.find(marker) second = text.find(marker, first + 1) if second != -1: trimmed = text[:second].rstrip() + "\n" path.write_text(trimmed, encoding="utf-8")