Skip to content

Commit 1eb6ce3

Browse files
committed
Implement skip_local_inventory option
1 parent 6cf34b9 commit 1eb6ce3

File tree

9 files changed

+89
-5
lines changed

9 files changed

+89
-5
lines changed

docs/usage/configuration/headings.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ With this option enabled, each function/method parameter
8888
(including parameters of `__init__` methods merged in their parent class
8989
with the [`merge_init_into_class`][] option)
9090
gets a permalink, an entry in the Table of Contents,
91-
and an entry in the generated objects inventory.
91+
and an entry in the generated objects inventory (unless [`skip_local_inventory`][] is enabled).
9292
The permalink and inventory entry allow cross-references
9393
from internal and external pages.
9494

@@ -664,6 +664,68 @@ plugins:
664664
////
665665
///
666666

667+
668+
[](){#option-skip_local_inventory}
669+
## `skip_local_inventory`
670+
671+
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
672+
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
673+
674+
Whether to not give objects local inventory entries and permalinks.
675+
676+
With this option enabled, re-rendering docstrings for objects from external inventories is possible with their cross-references pointing to the original external inventory, not local.
677+
678+
```yaml title="in mkdocs.yml (global configuration)"
679+
plugins:
680+
- mkdocstrings:
681+
handlers:
682+
python:
683+
options:
684+
skip_local_inventory: false
685+
```
686+
687+
```md title="or in docs/some_page.md (local configuration)"
688+
::: path.to.module
689+
options:
690+
skip_local_inventory: true
691+
```
692+
693+
/// admonition | Preview
694+
type: preview
695+
696+
697+
//// tab | With `skip_local_inventory`
698+
699+
```md exec="on"
700+
::: bisect.bisect_left
701+
options:
702+
heading_level: 3
703+
skip_local_inventory: false
704+
show_docstring_description: false
705+
```
706+
707+
Notice how [`bisect.bisect_left`][] now points to the section above.
708+
709+
////
710+
711+
//// tab | Without `skip_local_inventory`
712+
713+
```md exec="on"
714+
::: bisect.bisect_right
715+
inventories:
716+
- https://docs.python.org/3/objects.inv
717+
options:
718+
heading_level: 3
719+
skip_local_inventory: true
720+
show_docstring_description: false
721+
```
722+
723+
Notice how [`bisect.bisect_right`][] points to the original Python documentation.
724+
725+
////
726+
727+
///
728+
667729
[](){#option-toc_label}
668730
## `toc_label`
669731

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ format-command = "ruff format --config config/ruff.toml --stdin-filename {filena
122122

123123
[tool.uv]
124124
default-groups = ["maintain", "ci", "docs"]
125+
126+
[tool.uv.sources]
127+
mkdocstrings = { git = "https://github.com/mkdocstrings/mkdocstrings", rev = "bartosz/flag-skip-inventory" }

src/mkdocstrings_handlers/python/_internal/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,14 @@ class PythonInputOptions:
865865
),
866866
] = False
867867

868+
skip_local_inventory: Annotated[
869+
bool,
870+
_Field(
871+
group="headings",
872+
description="Whether to not give objects local inventory entries and permalinks.",
873+
),
874+
] = False
875+
868876
signature_crossrefs: Annotated[
869877
bool,
870878
_Field(

src/mkdocstrings_handlers/python/templates/material/_base/attribute.html.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Context:
4040
id=html_id,
4141
class="doc doc-heading",
4242
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute.name),
43+
skip_inventory=config.skip_local_inventory,
4344
) %}
4445

4546
{% block heading scoped %}
@@ -93,6 +94,7 @@ Context:
9394
id=html_id,
9495
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute_name),
9596
hidden=True,
97+
skip_inventory=config.skip_local_inventory,
9698
) %}
9799
{% endfilter %}
98100
{% endif %}

src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Context:
4545
) %}
4646
{% if attributes %}
4747
{% if config.show_category_heading %}
48-
{% filter heading(heading_level, id=html_id ~ "-attributes") %}Attributes{% endfilter %}
48+
{% filter heading(heading_level, id=html_id ~ "-attributes", skip_inventory=config.skip_local_inventory) %}Attributes{% endfilter %}
4949
{% endif %}
5050
{% with heading_level = heading_level + extra_level %}
5151
{% for attribute in attributes|order_members(config.members_order, members_list) %}
@@ -65,7 +65,7 @@ Context:
6565
) %}
6666
{% if classes %}
6767
{% if config.show_category_heading %}
68-
{% filter heading(heading_level, id=html_id ~ "-classes") %}Classes{% endfilter %}
68+
{% filter heading(heading_level, id=html_id ~ "-classes", skip_inventory=config.skip_local_inventory) %}Classes{% endfilter %}
6969
{% endif %}
7070
{% with heading_level = heading_level + extra_level %}
7171
{% for class in classes|order_members(config.members_order, members_list) %}
@@ -85,7 +85,7 @@ Context:
8585
) %}
8686
{% if functions %}
8787
{% if config.show_category_heading %}
88-
{% filter heading(heading_level, id=html_id ~ "-functions") %}Functions{% endfilter %}
88+
{% filter heading(heading_level, id=html_id ~ "-functions", skip_inventory=config.skip_local_inventory) %}Functions{% endfilter %}
8989
{% endif %}
9090
{% with heading_level = heading_level + extra_level %}
9191
{% for function in functions|order_members(config.members_order, members_list) %}
@@ -108,7 +108,7 @@ Context:
108108
) %}
109109
{% if modules %}
110110
{% if config.show_category_heading %}
111-
{% filter heading(heading_level, id=html_id ~ "-modules") %}Modules{% endfilter %}
111+
{% filter heading(heading_level, id=html_id ~ "-modules", skip_inventory=config.skip_local_inventory) %}Modules{% endfilter %}
112112
{% endif %}
113113
{% with heading_level = heading_level + extra_level %}
114114
{% for module in modules|order_members("alphabetical", members_list) %}

src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Context:
3939
id=html_id,
4040
class="doc doc-heading",
4141
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else class.name),
42+
skip_inventory=config.skip_local_inventory,
4243
) %}
4344

4445
{% block heading scoped %}
@@ -112,6 +113,7 @@ Context:
112113
id=html_id,
113114
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-class"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else class.name),
114115
hidden=True,
116+
skip_inventory=config.skip_local_inventory,
115117
) %}
116118
{% endfilter %}
117119
{% endif %}

src/mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Context:
4343
id=html_id ~ "(" ~ parameter.name ~ ")",
4444
class="doc doc-heading doc-heading-parameter",
4545
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-parameter"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + parameter.name,
46+
skip_inventory=config.skip_local_inventory,
4647
) %}
4748
<code>{{ parameter.name }}</code>
4849
{% endfilter %}
@@ -92,6 +93,7 @@ Context:
9293
id=html_id ~ "(" ~ parameter.name ~ ")",
9394
class="doc doc-heading doc-heading-parameter",
9495
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-parameter"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + parameter.name,
96+
skip_inventory=config.skip_local_inventory,
9597
) %}
9698
<b><code>{{ parameter.name }}</code></b>
9799
{% endfilter %}
@@ -139,6 +141,7 @@ Context:
139141
id=html_id ~ "(" ~ parameter.name ~ ")",
140142
class="doc doc-heading doc-heading-parameter",
141143
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-parameter"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + parameter.name,
144+
skip_inventory=config.skip_local_inventory,
142145
) %}
143146
<code>{{ parameter.name }}</code>
144147
{% endfilter %}

src/mkdocstrings_handlers/python/templates/material/_base/function.html.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Context:
4646
id=html_id,
4747
class="doc doc-heading",
4848
toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name),
49+
skip_inventory=config.skip_local_inventory,
4950
) %}
5051

5152
{% block heading scoped %}
@@ -110,6 +111,7 @@ Context:
110111
id=html_id,
111112
toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name),
112113
hidden=True,
114+
skip_inventory=config.skip_local_inventory,
113115
) %}
114116
{% endfilter %}
115117
{% endif %}

src/mkdocstrings_handlers/python/templates/material/_base/module.html.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Context:
3939
id=html_id,
4040
class="doc doc-heading",
4141
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else module.name),
42+
skip_inventory=config.skip_local_inventory,
4243
) %}
4344

4445
{% block heading scoped %}
@@ -76,6 +77,7 @@ Context:
7677
id=html_id,
7778
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else module.name),
7879
hidden=True,
80+
skip_inventory=config.skip_local_inventory,
7981
) %}
8082
{% endfilter %}
8183
{% endif %}

0 commit comments

Comments
 (0)