Skip to content

Commit 3133b63

Browse files
committed
Lint docstrings examples
Use the new utility functions to lint the examples in the code docstrings. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 971d088 commit 3133b63

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exclude CODEOWNERS
66
exclude CONTRIBUTING.md
77
exclude mkdocs.yml
88
exclude noxfile.py
9+
exclude src/conftest.py
910
recursive-exclude .github *
1011
recursive-exclude cookiecutter *
1112
recursive-exclude docs *

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ dev-mypy = [
8383
]
8484
dev-noxfile = ["nox == 2023.4.22"]
8585
dev-pylint = [
86-
"pylint == 2.17.3",
86+
# dev-pytest already defines a dependency to pylint because of the examples
8787
# For checking the noxfile, docs/ script, and tests
8888
"frequenz-repo-config[dev-mkdocs,dev-noxfile,dev-pytest]",
8989
]
9090
dev-pytest = [
91-
"pytest == 7.3.1",
91+
"pytest == 7.4.0",
92+
"pylint == 2.17.3", # We need this to check for the examples
9293
"cookiecutter == 2.1.1", # For checking the cookiecutter scripts
94+
"sybil == 5.0.3", # Should be consistent with the extra-lint-examples dependency
9395
]
9496
dev = [
9597
"frequenz-repo-config[dev-mkdocs,dev-docstrings,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
@@ -133,7 +135,7 @@ module = ["cookiecutter", "cookiecutter.*", "sybil", "sybil.*"]
133135
ignore_missing_imports = true
134136

135137
[tool.pytest.ini_options]
136-
testpaths = ["tests"]
138+
testpaths = ["src", "tests"]
137139
markers = [
138140
"integration: integration tests (deselect with '-m \"not integration\"')",
139141
]

src/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# License: MIT
2+
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Validate docstring code examples.
5+
6+
Code examples are often wrapped in triple backticks (```) within docstrings.
7+
This plugin extracts these code examples and validates them using pylint.
8+
"""
9+
10+
from sybil import Sybil
11+
12+
from frequenz.repo.config.pytest import examples
13+
14+
pytest_collect_file = Sybil(**examples.get_sybil_arguments()).pytest()

0 commit comments

Comments
 (0)