Skip to content

Commit 75136b9

Browse files
authored
feat(pytest-plugin): Add doc-pytest-plugin directive (#8)
Adds a higher-level `doc-pytest-plugin` directive to `sphinx-autodoc-pytest-fixtures` for building standard pytest plugin documentation pages. The directive generates a consistent frame — install block, `pytest11` autodiscovery note, fixture summary and reference — owned in one place so the prose propagates to every downstream build automatically. - **New directive** `doc-pytest-plugin`: required `:package:`, optional `:project:`, `:summary:`, `:tests-url:`, and `:install-command:`. Body content is free-form (sections, prose, code blocks); the frame is opinionated. Use the manual `autofixture-index` + `autofixtures` recipe when custom layout or section ordering is needed ("power path"). - **Removed** `:mode:` — `reference` mode duplicated the manual recipe, undermining the abstraction. - **Relaxed** `:summary:` and `:project:` to optional. Missing `:summary:` suppresses the intro paragraph (no empty `<p>`). Missing `:project:` falls back to generic "test suite" link text; the package-slug default was a deliberate non-option. - **Fixed** `NameError` crash in `_build_fixture_section_nodes`: `_build_doc_pytest_plugin_index_node` had been removed but its call site was not updated, crashing every docs build. - **Fixed** `sphinx-build -W` docs warnings: replaced `_is_markdown_source` (file-extension check) with `_is_native_myst` (`isinstance(state, MockState)`) so directives inside `{eval-rst}` blocks are not wrapped in a backtick fence before being passed to RST's `nested_parse`. - **Added** `:no-index:` flag to `autofixtures::` for pages that describe the same module in multiple sections. - **Tests**: coverage for generic `:project:` link text, optional `:summary:`, and hard failure on missing `:package:`. - **Docs**: "When to use" and "Manual recipe" sections added.
2 parents 54ffa23 + 4e6e1d6 commit 75136b9

File tree

6 files changed

+641
-78
lines changed

6 files changed

+641
-78
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ $ uv add gp-sphinx --prerelease allow
3434
badges, classified dependency lists, reverse-dep tracking, and auto-generated
3535
usage snippets. Frozen dataclasses for pickle-safe incremental builds, parallel-safe,
3636
WCAG AA badge contrast, and pytest 9+ compatible.
37+
New: `doc-pytest-plugin` directive generates a standard pytest plugin page
38+
(install block, `pytest11` autodiscovery note, fixture summary and reference)
39+
from a single directive call. Optional `:project:`, `:summary:`, `:tests-url:`,
40+
and `:install-command:` options; body is free-form. Use `autofixture-index` +
41+
`autofixtures` directly when custom layout is needed.
3742
- `sphinx-fonts` — Self-hosted web fonts via Fontsource CDN. Downloads at build time,
3843
caches locally, and injects `@font-face` CSS with preload hints and fallback
3944
font-metric overrides for zero-CLS loading.

docs/packages/sphinx-autodoc-pytest-fixtures.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
Sphinx extension for documenting pytest fixtures as first-class objects. It
66
registers a Python-domain fixture directive and role, autodoc helpers for bulk
7-
fixture discovery, and the badge/index UI used throughout the page below.
7+
fixture discovery, a higher-level pytest plugin page helper, and the
8+
badge/index UI used throughout the page below.
89

910
```console
1011
$ pip install sphinx-autodoc-pytest-fixtures
@@ -49,14 +50,49 @@ pytest_external_fixture_links = {
4950

5051
```{eval-rst}
5152
.. autofixtures:: spf_demo_fixtures
53+
:no-index:
54+
```
55+
56+
### Plugin page helper
57+
58+
:::{doc-pytest-plugin} spf_demo_fixtures
59+
:package: sphinx-autodoc-pytest-fixtures
60+
61+
Add project-specific usage notes here. The helper renders the install
62+
section, autodiscovery note, and full fixture summary/reference.
63+
:::
64+
65+
#### When to use `doc-pytest-plugin`
66+
67+
Use this directive for a standard pytest plugin page where you want consistent
68+
house-style: an install section, the `pytest11` autodiscovery note, and a
69+
generated fixture summary and reference.
70+
71+
#### Manual recipe (power path)
72+
73+
When you need custom layout — a different section order, content between the
74+
summary and reference, or no install block — use the low-level directives
75+
directly:
76+
77+
````markdown
78+
## Fixture Summary
79+
80+
```{autofixture-index} libvcs.pytest_plugin
81+
```
82+
83+
## Fixture Reference
84+
85+
```{autofixtures} libvcs.pytest_plugin
5286
```
87+
````
5388

5489
#### autofixtures options
5590

5691
| Option | Default | Description |
5792
|--------|---------|-------------|
5893
| `:order:` | `"source"` | `"source"` preserves module order; `"alpha"` sorts alphabetically |
5994
| `:exclude:` | (empty) | Comma-separated fixture names to skip |
95+
| `:no-index:` | (off) | Emit descriptions without registering fixtures in the domain index; use when the same module is documented twice on one page |
6096

6197
#### autofixture-index options
6298

packages/sphinx-autodoc-pytest-fixtures/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Then document fixtures with:
2424
.. autofixtures:: myproject.conftest
2525
2626
.. autofixture-index:: myproject.conftest
27+
28+
.. doc-pytest-plugin:: myproject.pytest_plugin
29+
:project: myproject
30+
:package: myproject
31+
:summary: Document your pytest plugin with generated install and fixture
32+
reference sections.
2733
```
2834

2935
## Documentation

packages/sphinx-autodoc-pytest-fixtures/src/sphinx_autodoc_pytest_fixtures/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from sphinx_autodoc_pytest_fixtures._directives import (
5454
AutofixtureIndexDirective,
5555
AutofixturesDirective,
56+
DocPytestPluginDirective,
5657
PyFixtureDirective,
5758
)
5859
from sphinx_autodoc_pytest_fixtures._documenter import FixtureDocumenter
@@ -174,6 +175,7 @@ def _add_static_path(app: Sphinx) -> None:
174175
app.add_directive("autofixtures", AutofixturesDirective)
175176
app.add_node(autofixture_index_node)
176177
app.add_directive("autofixture-index", AutofixtureIndexDirective)
178+
app.add_directive("doc-pytest-plugin", DocPytestPluginDirective)
177179

178180
app.connect("missing-reference", _on_missing_reference)
179181
app.connect("doctree-resolved", _on_doctree_resolved)

0 commit comments

Comments
 (0)