Skip to content

Commit 45d1949

Browse files
committed
Fix wrongly located paths key in mkdocs.yml
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent b8e38dc commit 45d1949

File tree

9 files changed

+70
-8
lines changed

9 files changed

+70
-8
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ But you might still need to adapt your code:
3535

3636
### Cookiecutter template
3737

38-
<!-- Here bug fixes for cookiecutter specifically -->
38+
- mkdocstrings: Move `paths` key to the right section in `mkdocs.yml`.

cookiecutter/migrate.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,65 @@ 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+
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+
162224
def apply_patch(patch_content: str) -> None:
163225
"""Apply a patch using the patch utility."""
164226
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

cookiecutter/{{cookiecutter.github_repo_name}}/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["{{cookiecutter | src_path}}"]
106107
options:
107-
paths: ["{{cookiecutter | src_path}}"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ plugins:
101101
default_handler: python
102102
handlers:
103103
python:
104+
paths: ["src"]
104105
options:
105-
paths: ["src"]
106106
docstring_section_style: spacy
107107
inherited_members: true
108108
merge_init_into_class: false

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["src"]
106107
options:
107-
paths: ["src"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["py"]
106107
options:
107-
paths: ["py"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["src"]
106107
options:
107-
paths: ["src"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["src"]
106107
options:
107-
paths: ["src"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ plugins:
103103
default_handler: python
104104
handlers:
105105
python:
106+
paths: ["src"]
106107
options:
107-
paths: ["src"]
108108
docstring_section_style: spacy
109109
inherited_members: true
110110
merge_init_into_class: false

0 commit comments

Comments
 (0)