@@ -42,6 +42,9 @@ def main() -> None:
4242 "mkdocs.yml" , " import:" , " inventories:"
4343 )
4444 print ("=" * 72 )
45+ print ("Fixing wrongly located `paths` keys in mkdocs.yml..." )
46+ migrate_mkdocs_yaml (Path ("mkdocs.yml" ))
47+ print ("=" * 72 )
4548 print ("Migration script finished. Remember to follow any manual instructions." )
4649 print ("=" * 72 )
4750
@@ -159,6 +162,64 @@ def migrate_filterwarnings(path: Path) -> None:
159162 )
160163
161164
165+ def migrate_mkdocs_yaml (file_path : Path ) -> None :
166+ """Migrate the mkdocs.yml file to fix the `paths` key location."""
167+ if not file_path .is_file ():
168+ return
169+
170+ python_section = " python:"
171+ options_section = " options:"
172+ bad_paths_config = " paths:"
173+
174+ lines = file_path .read_text (encoding = "utf-8" ).splitlines (keepends = True )
175+ needs_migration = False
176+ paths = ""
177+ in_python = False
178+ in_options = False
179+
180+ # 1) Detect whether there's a python_section followed by options_section
181+ # and then bad_paths_config in that block.
182+ for line in lines :
183+ if line .startswith (python_section ):
184+ in_python = True
185+ in_options = False
186+ continue
187+ if in_python and line .startswith (options_section ):
188+ in_options = True
189+ continue
190+ if in_options and line .startswith (bad_paths_config ):
191+ needs_migration = True
192+ paths = line [len (bad_paths_config ) :].strip ()
193+ break
194+ # If indentation drops back below python-level, stop looking in this block
195+ if in_python and not line .startswith (" " ) and not line .isspace ():
196+ in_python = False
197+ in_options = False
198+
199+ if not needs_migration :
200+ return
201+
202+ # 2) Perform the line-based rewrite:
203+ new_lines : list [str ] = []
204+ inserted_paths = False
205+
206+ for line in lines :
207+ # When we hit the python_section line, insert new paths config directly under it
208+ if line .startswith (python_section ) and not inserted_paths :
209+ new_lines .append (line )
210+ new_lines .append (f" paths: { paths } \n " )
211+ inserted_paths = True
212+ continue
213+
214+ # After inserting, drop the old " paths:" line
215+ if inserted_paths and line .startswith (bad_paths_config ):
216+ continue
217+
218+ new_lines .append (line )
219+
220+ file_path .write_text ("" .join (new_lines ), encoding = "utf-8" )
221+
222+
162223def apply_patch (patch_content : str ) -> None :
163224 """Apply a patch using the patch utility."""
164225 subprocess .run (["patch" , "-p1" ], input = patch_content .encode (), check = True )
0 commit comments