@@ -39,10 +39,71 @@ def main() -> None:
3939 "mkdocs.yml" , " import:" , " inventories:"
4040 )
4141 print ("=" * 72 )
42+ print ("Fixing wrongly located `paths` keys in mkdocs.yml..." )
43+ migrate_mkdocs_yaml (Path ("mkdocs.yml" ))
44+ print ("=" * 72 )
4245 print ("Migration script finished. Remember to follow any manual instructions." )
4346 print ("=" * 72 )
4447
4548
49+ def migrate_mkdocs_yaml (file_path : Path ) -> None :
50+ """Migrate the mkdocs.yml file to fix the `paths` key location."""
51+ if not file_path .is_file ():
52+ return
53+
54+ python_section = " python:"
55+ options_section = " options:"
56+ bad_paths_config = " paths:"
57+
58+ lines = file_path .read_text (encoding = "utf-8" ).splitlines (keepends = True )
59+ needs_migration = False
60+ paths = ""
61+ in_python = False
62+ in_options = False
63+
64+ # 1) Detect whether there's a python_section followed by options_section
65+ # and then bad_paths_config in that block.
66+ for line in lines :
67+ if line .startswith (python_section ):
68+ in_python = True
69+ in_options = False
70+ continue
71+ if in_python and line .startswith (options_section ):
72+ in_options = True
73+ continue
74+ if in_options and line .startswith (bad_paths_config ):
75+ needs_migration = True
76+ paths = line [len (bad_paths_config ) :].strip ()
77+ break
78+ # If indentation drops back below python-level, stop looking in this block
79+ if in_python and not line .startswith (" " ) and not line .isspace ():
80+ in_python = False
81+ in_options = False
82+
83+ if not needs_migration :
84+ return
85+
86+ # 2) Perform the line-based rewrite:
87+ new_lines : list [str ] = []
88+ inserted_paths = False
89+
90+ for line in lines :
91+ # When we hit the python_section line, insert new paths config directly under it
92+ if line .startswith (python_section ) and not inserted_paths :
93+ new_lines .append (line )
94+ new_lines .append (f" paths: { paths } \n " )
95+ inserted_paths = True
96+ continue
97+
98+ # After inserting, drop the old " paths:" line
99+ if inserted_paths and line .startswith (bad_paths_config ):
100+ continue
101+
102+ new_lines .append (line )
103+
104+ file_path .write_text ("" .join (new_lines ), encoding = "utf-8" )
105+
106+
46107def apply_patch (patch_content : str ) -> None :
47108 """Apply a patch using the patch utility."""
48109 subprocess .run (["patch" , "-p1" ], input = patch_content .encode (), check = True )
0 commit comments