@@ -39,10 +39,74 @@ 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+ """
51+ Inspect a mkdocs.yml file textually and, if it defines `paths` under
52+ `plugins: -> mkdocstrings: -> handlers: -> python: -> options:`,
53+ rewrite the file in place to move `paths` directly under `python:`
54+ and remove the old `options:` and its `paths:` line. This uses only
55+ line-based detection (no external dependencies).
56+
57+ Args:
58+ file_path: Path to the mkdocs.yml file to migrate.
59+ """
60+ if not file_path .is_file ():
61+ return
62+
63+ lines = file_path .read_text (encoding = "utf-8" ).splitlines (keepends = True )
64+ needs_migration = False
65+ in_python = False
66+ in_options = False
67+
68+ # 1) Detect whether there's a " python:" followed by " options:"
69+ # and then " paths:" in that block.
70+ for line in lines :
71+ if line .startswith (" python:" ):
72+ in_python = True
73+ in_options = False
74+ continue
75+ if in_python and line .startswith (" options:" ):
76+ in_options = True
77+ continue
78+ if in_options and line .startswith (" paths:" ):
79+ needs_migration = True
80+ break
81+ # If indentation drops back below python-level, stop looking in this block
82+ if in_python and not line .startswith (" " ) and not line .isspace ():
83+ in_python = False
84+ in_options = False
85+
86+ if not needs_migration :
87+ return
88+
89+ # 2) Perform the line-based rewrite:
90+ new_lines : list [str ] = []
91+ inserted_paths = False
92+
93+ for line in lines :
94+ # When we hit the " python:" line, insert new " paths:" directly under it
95+ if line .startswith (" python:" ) and not inserted_paths :
96+ new_lines .append (line )
97+ new_lines .append (' paths: ["src"]\n ' )
98+ inserted_paths = True
99+ continue
100+
101+ # After inserting, drop the old " paths:" line
102+ if inserted_paths and line .startswith (" paths:" ):
103+ continue
104+
105+ new_lines .append (line )
106+
107+ file_path .write_text ("" .join (new_lines ), encoding = "utf-8" )
108+
109+
46110def apply_patch (patch_content : str ) -> None :
47111 """Apply a patch using the patch utility."""
48112 subprocess .run (["patch" , "-p1" ], input = patch_content .encode (), check = True )
0 commit comments