Skip to content

Commit 0a31c4a

Browse files
mdellwegpedro-psb
authored andcommitted
Add flag to disable docstrings plugin
1 parent bf89693 commit 0a31c4a

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/pulp_docs/cli.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import click
22

33
from mkdocs.__main__ import cli as mkdocs_cli
4-
from pulp_docs.context import ctx_blog, ctx_draft
4+
from pulp_docs.context import ctx_blog, ctx_docstrings, ctx_draft
55

66

77
def blog_callback(ctx: click.Context, param: click.Parameter, value: bool) -> bool:
88
ctx_blog.set(value)
99
return value
1010

1111

12+
def docstrings_callback(
13+
ctx: click.Context, param: click.Parameter, value: bool
14+
) -> bool:
15+
ctx_docstrings.set(value)
16+
return value
17+
18+
1219
def draft_callback(ctx: click.Context, param: click.Parameter, value: bool) -> bool:
1320
ctx_draft.set(value)
1421
return value
@@ -19,7 +26,14 @@ def draft_callback(ctx: click.Context, param: click.Parameter, value: bool) -> b
1926
default=True,
2027
expose_value=False,
2128
callback=blog_callback,
22-
help="Don't fail if repositories are missing.",
29+
help="Build blog.",
30+
)
31+
docstrings_option = click.option(
32+
"--docstrings/--no-docstrings",
33+
default=True,
34+
expose_value=False,
35+
callback=docstrings_callback,
36+
help="Enable mkdocstrings plugin.",
2337
)
2438

2539
draft_option = click.option(
@@ -31,9 +45,8 @@ def draft_callback(ctx: click.Context, param: click.Parameter, value: bool) -> b
3145

3246
main = mkdocs_cli
3347

34-
build_command = main.commands.get("build")
35-
serve_command = main.commands.get("serve")
36-
draft_option(build_command)
37-
draft_option(serve_command)
38-
blog_option(build_command)
39-
blog_option(serve_command)
48+
for command_name in ["build", "serve"]:
49+
sub_command = main.commands.get(command_name)
50+
draft_option(sub_command)
51+
blog_option(sub_command)
52+
docstrings_option(sub_command)

src/pulp_docs/context.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33

44
ctx_blog = ContextVar("ctx_blog", default=True)
5+
ctx_docstrings = ContextVar("ctx_docstrings", default=True)
56
ctx_draft = ContextVar("ctx_draft", default=False)

src/pulp_docs/plugin.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from mkdocs.structure.pages import Page
1616
from mkdocs.utils.templates import TemplateContext
1717

18-
from pulp_docs.context import ctx_blog, ctx_draft
18+
from pulp_docs.context import ctx_blog, ctx_docstrings, ctx_draft
1919

2020
log = get_plugin_logger(__name__)
2121

@@ -229,6 +229,7 @@ class PulpDocsPlugin(BasePlugin[PulpDocsPluginConfig]):
229229
def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
230230
# Two directories up from docs is where we expect all the other repositories.
231231
self.blog = ctx_blog.get()
232+
self.docstrings = ctx_docstrings.get()
232233
self.draft = ctx_draft.get()
233234

234235
self.pulp_docs_dir = Path(config.docs_dir).parent
@@ -260,6 +261,9 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig | None:
260261
blog_plugin = config.plugins["material/blog"]
261262
blog_plugin.config["enabled"] = self.blog
262263

264+
mkdocstrings_plugin = config.plugins["mkdocstrings"]
265+
mkdocstrings_plugin.config["enabled"] = self.docstrings
266+
263267
return config
264268

265269
def on_files(self, files: Files, /, *, config: MkDocsConfig) -> Files | None:

0 commit comments

Comments
 (0)