Skip to content

Commit 7b81bb1

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

File tree

9 files changed

+63
-8
lines changed

9 files changed

+63
-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 rigth section in `mkdocs.yml`.

cookiecutter/migrate.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,65 @@ 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+
lines = file_path.read_text(encoding="utf-8").splitlines(keepends=True)
55+
needs_migration = False
56+
in_python = False
57+
in_options = False
58+
59+
# 1) Detect whether there's a " python:" followed by " options:"
60+
# and then " paths:" in that block.
61+
for line in lines:
62+
if line.startswith(" python:"):
63+
in_python = True
64+
in_options = False
65+
continue
66+
if in_python and line.startswith(" options:"):
67+
in_options = True
68+
continue
69+
if in_options and line.startswith(" paths:"):
70+
needs_migration = True
71+
break
72+
# If indentation drops back below python-level, stop looking in this block
73+
if in_python and not line.startswith(" ") and not line.isspace():
74+
in_python = False
75+
in_options = False
76+
77+
if not needs_migration:
78+
return
79+
80+
# 2) Perform the line-based rewrite:
81+
new_lines: list[str] = []
82+
inserted_paths = False
83+
84+
for line in lines:
85+
# When we hit the " python:" line, insert new " paths:" directly under it
86+
if line.startswith(" python:") and not inserted_paths:
87+
new_lines.append(line)
88+
new_lines.append(' paths: ["src"]\n')
89+
inserted_paths = True
90+
continue
91+
92+
# After inserting, drop the old " paths:" line
93+
if inserted_paths and line.startswith(" paths:"):
94+
continue
95+
96+
new_lines.append(line)
97+
98+
file_path.write_text("".join(new_lines), encoding="utf-8")
99+
100+
46101
def apply_patch(patch_content: str) -> None:
47102
"""Apply a patch using the patch utility."""
48103
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)