Skip to content

Commit 213e42a

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

File tree

9 files changed

+69
-8
lines changed

9 files changed

+69
-8
lines changed

RELEASE_NOTES.md

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

3535
### Cookiecutter template
3636

37-
<!-- Here bug fixes for cookiecutter specifically -->
37+
- 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
@@ -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+
46107
def 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)

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)