Skip to content

Commit d96d1ea

Browse files
committed
Fix wrongly located paths key in mkdocs.yml
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent b8e38dc commit d96d1ea

9 files changed

Lines changed: 69 additions & 8 deletions

File tree

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: 61 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,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+
162223
def 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)

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)