@@ -34,6 +34,16 @@ def main() -> None:
3434 # Add a separation line like this one after each migration step.
3535 print ("=" * 72 )
3636 migrate_filterwarnings (Path ("pyproject.toml" ))
37+ print (
38+ "Renaming the deprecated mkdocstrings `import` to `inventories` in `mkdocs.yml`..."
39+ )
40+ print ("=" * 72 )
41+ replace_file_contents_atomically (
42+ "mkdocs.yml" , " import:" , " inventories:"
43+ )
44+ print ("=" * 72 )
45+ print ("Fixing wrongly located `paths` keys in mkdocs.yml..." )
46+ migrate_mkdocs_yaml (Path ("mkdocs.yml" ))
3747 print ("=" * 72 )
3848 print ("Migration script finished. Remember to follow any manual instructions." )
3949 print ("=" * 72 )
@@ -152,6 +162,65 @@ def migrate_filterwarnings(path: Path) -> None:
152162 )
153163
154164
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+ manual_step (f"File { file_path } does not exist, skipping automatic migration." )
169+ return
170+
171+ python_section = " python:"
172+ options_section = " options:"
173+ bad_paths_config = " paths:"
174+
175+ lines = file_path .read_text (encoding = "utf-8" ).splitlines (keepends = True )
176+ needs_migration = False
177+ paths = ""
178+ in_python = False
179+ in_options = False
180+
181+ # 1) Detect whether there's a python_section followed by options_section
182+ # and then bad_paths_config in that block.
183+ for line in lines :
184+ if line .startswith (python_section ):
185+ in_python = True
186+ in_options = False
187+ continue
188+ if in_python and line .startswith (options_section ):
189+ in_options = True
190+ continue
191+ if in_options and line .startswith (bad_paths_config ):
192+ needs_migration = True
193+ paths = line [len (bad_paths_config ) :].strip ()
194+ break
195+ # If indentation drops back below python-level, stop looking in this block
196+ if in_python and not line .startswith (" " ) and not line .isspace ():
197+ in_python = False
198+ in_options = False
199+
200+ if not needs_migration :
201+ return
202+
203+ # 2) Perform the line-based rewrite:
204+ new_lines : list [str ] = []
205+ inserted_paths = False
206+
207+ for line in lines :
208+ # When we hit the python_section line, insert new paths config directly under it
209+ if line .startswith (python_section ) and not inserted_paths :
210+ new_lines .append (line )
211+ new_lines .append (f" paths: { paths } \n " )
212+ inserted_paths = True
213+ continue
214+
215+ # After inserting, drop the old " paths:" line
216+ if inserted_paths and line .startswith (bad_paths_config ):
217+ continue
218+
219+ new_lines .append (line )
220+
221+ file_path .write_text ("" .join (new_lines ), encoding = "utf-8" )
222+
223+
155224def apply_patch (patch_content : str ) -> None :
156225 """Apply a patch using the patch utility."""
157226 subprocess .run (["patch" , "-p1" ], input = patch_content .encode (), check = True )
0 commit comments