Skip to content

Commit f7f7694

Browse files
authored
Add support for mkdocstrings-python v2 (#481)
Fixes #482, #483, #357.
2 parents fbe09b0 + 99511e2 commit f7f7694

File tree

15 files changed

+45
-22
lines changed

15 files changed

+45
-22
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ But you might still need to adapt your code:
2222

2323
## New Features
2424

25-
<!-- Here goes the main new features and examples or instructions on how to use them -->
25+
* `mkdocsstrings-python` v2 is now supported.
2626

2727
### Cookiecutter template
2828

@@ -31,6 +31,8 @@ But you might still need to adapt your code:
3131
- Dependencies have been updated.
3232
- Added Dependabot auto-merge workflow using `frequenz-floss/dependabot-auto-approve` action.
3333
- Migration script now creates auto-merge workflow and disables CODEOWNERS review requirement via GitHub API.
34+
- The `import` key in `mkdocs.yml` under `mkdocstrings` has to be renamed to `inventories`.
35+
- The `paths` key in `mkdocs.yml` under `mkdocstrings` has to be moved from the `options` key to the `python` key.
3436

3537
## Bug Fixes
3638

cookiecutter/migrate.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,31 @@ def main() -> None:
3939
print("Disabling CODEOWNERS review requirement in GitHub ruleset...")
4040
disable_codeowners_review_requirement()
4141
print("=" * 72)
42+
print("Updating the mkdocs.yml for mkdocstrings-python v2 compatibility...")
43+
update_mkdocs_yml_mkdocstrings_python_v2()
44+
print("=" * 72)
4245
print("Migration script finished. Remember to follow any manual instructions.")
4346
print("=" * 72)
4447

4548

49+
def update_mkdocs_yml_mkdocstrings_python_v2() -> None:
50+
"""Rename 'inventories' imports to 'inventory'."""
51+
replace_file_contents_atomically(
52+
filepath=Path("mkdocs.yml"),
53+
old=" import:",
54+
new=" inventories:",
55+
)
56+
replace_file_contents_atomically(
57+
filepath=Path("mkdocs.yml"),
58+
old="""\
59+
options:
60+
paths: ["src"]""",
61+
new="""\
62+
paths: ["src"]
63+
options:""",
64+
)
65+
66+
4667
def create_dependabot_auto_merge_workflow() -> None:
4768
"""Create the Dependabot auto-merge workflow file."""
4869
workflow_dir = Path(".github") / "workflows"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ plugins:
102102
- mkdocstrings:
103103
default_handler: python
104104
handlers:
105+
paths: ["{{cookiecutter | src_path}}"]
105106
python:
106-
paths: ["{{cookiecutter | src_path}}"]
107107
options:
108108
docstring_section_style: spacy
109109
inherited_members: true

cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ dev-mkdocs = [
9999
"mkdocs-literate-nav == 0.6.2",
100100
"mkdocs-macros-plugin == 1.3.9",
101101
"mkdocs-material == 9.6.18",
102-
"mkdocstrings[python] == 0.30.0",
103-
"mkdocstrings-python == 1.17.0",
102+
"mkdocstrings[python] == 1.0.0",
103+
"mkdocstrings-python == 2.0.1",
104104
"frequenz-repo-config[{{cookiecutter.type}}] == 0.13.1",
105105
]
106106
dev-mypy = [

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"mkdocs-gen-files >= 0.4.0, < 0.6.0",
4242
"semver >= 3.0.1, < 4",
4343
"github-action-utils >= 1.1.0, < 2",
44-
"mkdocstrings-python >= 1.14.6, < 2",
44+
"mkdocstrings-python >= 1.14.6, < 3",
4545
]
4646
dynamic = ["version"]
4747

@@ -83,8 +83,8 @@ dev-mkdocs = [
8383
"mkdocs-literate-nav == 0.6.2",
8484
"mkdocs-macros-plugin == 1.4.0",
8585
"mkdocs-material == 9.6.21",
86-
"mkdocstrings[python] == 0.30.1",
87-
"mkdocstrings-python == 1.18.2",
86+
"mkdocstrings[python] == 1.0.0",
87+
"mkdocstrings-python == 2.0.1",
8888
]
8989
dev-mypy = [
9090
"mypy == 1.18.2",

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
@@ -102,8 +102,8 @@ plugins:
102102
- mkdocstrings:
103103
default_handler: python
104104
handlers:
105+
paths: ["src"]
105106
python:
106-
paths: ["src"]
107107
options:
108108
docstring_section_style: spacy
109109
inherited_members: true

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ dev-mkdocs = [
5858
"mkdocs-literate-nav == 0.6.2",
5959
"mkdocs-macros-plugin == 1.3.9",
6060
"mkdocs-material == 9.6.18",
61-
"mkdocstrings[python] == 0.30.0",
62-
"mkdocstrings-python == 1.17.0",
61+
"mkdocstrings[python] == 1.0.0",
62+
"mkdocstrings-python == 2.0.1",
6363
"frequenz-repo-config[actor] == 0.13.1",
6464
]
6565
dev-mypy = [

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
@@ -102,8 +102,8 @@ plugins:
102102
- mkdocstrings:
103103
default_handler: python
104104
handlers:
105+
paths: ["py"]
105106
python:
106-
paths: ["py"]
107107
options:
108108
docstring_section_style: spacy
109109
inherited_members: true

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ dev-mkdocs = [
6969
"mkdocs-literate-nav == 0.6.2",
7070
"mkdocs-macros-plugin == 1.3.9",
7171
"mkdocs-material == 9.6.18",
72-
"mkdocstrings[python] == 0.30.0",
73-
"mkdocstrings-python == 1.17.0",
72+
"mkdocstrings[python] == 1.0.0",
73+
"mkdocstrings-python == 2.0.1",
7474
"frequenz-repo-config[api] == 0.13.1",
7575
]
7676
dev-mypy = [

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
@@ -102,8 +102,8 @@ plugins:
102102
- mkdocstrings:
103103
default_handler: python
104104
handlers:
105+
paths: ["src"]
105106
python:
106-
paths: ["src"]
107107
options:
108108
docstring_section_style: spacy
109109
inherited_members: true

0 commit comments

Comments
 (0)