Skip to content

Commit b889607

Browse files
committed
👌 Improve allow rendering in non-standalone mode
1 parent 0122b58 commit b889607

File tree

6 files changed

+27
-36
lines changed

6 files changed

+27
-36
lines changed

docs/apidocs/autodoc2/autodoc2.render.base.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Classes
2323
API
2424
~~~
2525

26-
.. py:class:: RendererBase(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None)
26+
.. py:class:: RendererBase(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None, standalone: bool = True)
2727
:canonical: autodoc2.render.base.RendererBase
2828

2929
Bases: :py:obj:`abc.ABC`
@@ -62,6 +62,13 @@ API
6262
.. autodoc2-docstring:: autodoc2.render.base.RendererBase.config
6363
:parser:
6464

65+
.. py:property:: standalone
66+
:canonical: autodoc2.render.base.RendererBase.standalone
67+
:type: bool
68+
69+
.. autodoc2-docstring:: autodoc2.render.base.RendererBase.standalone
70+
:parser:
71+
6572
.. py:method:: warn(msg: str, type_: autodoc2.utils.WarningSubtypes = WarningSubtypes.RENDER_ERROR) -> None
6673
:canonical: autodoc2.render.base.RendererBase.warn
6774

docs/apidocs/autodoc2/autodoc2.render.myst_.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ API
4040

4141
.. autodoc2-docstring:: autodoc2.render.myst_._RE_DELIMS
4242

43-
.. py:class:: MystRenderer(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None)
43+
.. py:class:: MystRenderer(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None, standalone: bool = True)
4444
:canonical: autodoc2.render.myst_.MystRenderer
4545

4646
Bases: :py:obj:`autodoc2.render.base.RendererBase`

docs/apidocs/autodoc2/autodoc2.render.rst_.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ API
4040

4141
.. autodoc2-docstring:: autodoc2.render.rst_._RE_DELIMS
4242

43-
.. py:class:: RstRenderer(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None)
43+
.. py:class:: RstRenderer(db: autodoc2.db.Database, config: autodoc2.config.Config, warn: typing.Callable[[str, autodoc2.utils.WarningSubtypes], None] | None = None, resolved_all: dict[str, autodoc2.utils.ResolvedDict] | None = None, standalone: bool = True)
4444
:canonical: autodoc2.render.rst_.RstRenderer
4545

4646
Bases: :py:obj:`autodoc2.render.base.RendererBase`

src/autodoc2/render/base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ def __init__(
2727
config: Config,
2828
warn: t.Callable[[str, WarningSubtypes], None] | None = None,
2929
resolved_all: dict[str, ResolvedDict] | None = None,
30+
standalone: bool = True,
3031
) -> None:
31-
"""Initialise the renderer."""
32+
"""Initialise the renderer.
33+
34+
:param db: The database to obtain objects from.
35+
:param config: The configuration.
36+
:param warn: A function to call when a warning is encountered.
37+
:param resolved_all: A dictionary of full_name -> __all__ resolution.
38+
:param standalone: If True, this renderer is being used to create a standalone document
39+
"""
3240
self._db = db
3341
self._config = config
42+
self._standalone = standalone
3443
self._warn = warn or (lambda msg, type_: None)
3544
self._resolved_all = resolved_all
3645
self._resolve_all_warned: set[str] = set()
@@ -43,6 +52,11 @@ def config(self) -> Config:
4352
"""The configuration."""
4453
return self._config
4554

55+
@property
56+
def standalone(self) -> bool:
57+
"""If True, this renderer is being used to create a standalone document."""
58+
return self._standalone
59+
4660
def warn(
4761
self, msg: str, type_: WarningSubtypes = WarningSubtypes.RENDER_ERROR
4862
) -> None:

src/autodoc2/render/myst_.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def enclosing_backticks(text: str) -> str:
6666

6767
def render_package(self, item: ItemData) -> t.Iterable[str]:
6868
"""Create the content for a package."""
69-
if self.is_hidden(item):
69+
if self.standalone and self.is_hidden(item):
7070
yield from ["---", "orphan: true", "---", ""]
7171

7272
full_name = item["full_name"]
@@ -164,9 +164,6 @@ def render_module(self, item: ItemData) -> t.Iterable[str]:
164164

165165
def render_function(self, item: ItemData) -> t.Iterable[str]:
166166
"""Create the content for a function."""
167-
if self.is_hidden(item):
168-
return
169-
170167
short_name = item["full_name"].split(".")[-1]
171168
show_annotations = self.show_annotations(item)
172169
sig = f"{short_name}({self.format_args(item['args'], show_annotations)})"
@@ -196,9 +193,6 @@ def render_exception(self, item: ItemData) -> t.Iterable[str]:
196193

197194
def render_class(self, item: ItemData) -> t.Iterable[str]:
198195
"""Create the content for a class."""
199-
if self.is_hidden(item):
200-
return
201-
202196
short_name = item["full_name"].split(".")[-1]
203197
constructor = self.get_item(f"{item['full_name']}.__init__")
204198
sig = short_name
@@ -270,9 +264,6 @@ def render_class(self, item: ItemData) -> t.Iterable[str]:
270264

271265
def render_property(self, item: ItemData) -> t.Iterable[str]:
272266
"""Create the content for a property."""
273-
if self.is_hidden(item):
274-
return
275-
276267
short_name = item["full_name"].split(".")[-1]
277268
yield f"````{{py:property}} {short_name}"
278269
yield f":canonical: {item['full_name']}"
@@ -295,9 +286,6 @@ def render_property(self, item: ItemData) -> t.Iterable[str]:
295286

296287
def render_method(self, item: ItemData) -> t.Iterable[str]:
297288
"""Create the content for a method."""
298-
if self.is_hidden(item):
299-
return
300-
301289
short_name = item["full_name"].split(".")[-1]
302290
show_annotations = self.show_annotations(item)
303291
sig = f"{short_name}({self.format_args(item['args'], show_annotations, ignore_self='self')})"
@@ -329,9 +317,6 @@ def render_attribute(self, item: ItemData) -> t.Iterable[str]:
329317

330318
def render_data(self, item: ItemData) -> t.Iterable[str]:
331319
"""Create the content for a data item."""
332-
if self.is_hidden(item):
333-
return
334-
335320
short_name = item["full_name"].split(".")[-1]
336321

337322
yield f"````{{py:{item['type']}}} {short_name}"

src/autodoc2/render/rst_.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def generate_summary(self, items: list[ItemData]) -> t.Iterable[str]:
5858

5959
def render_package(self, item: ItemData) -> t.Iterable[str]:
6060
"""Create the content for a package."""
61-
if self.is_hidden(item):
61+
if self.standalone and self.is_hidden(item):
6262
yield from [":orphan:", ""]
6363

6464
full_name = item["full_name"]
@@ -154,9 +154,6 @@ def render_module(self, item: ItemData) -> t.Iterable[str]:
154154

155155
def render_function(self, item: ItemData) -> t.Iterable[str]:
156156
"""Create the content for a function."""
157-
if self.is_hidden(item):
158-
return
159-
160157
short_name = item["full_name"].split(".")[-1]
161158
show_annotations = self.show_annotations(item)
162159
sig = f"{short_name}({self.format_args(item['args'], show_annotations)})"
@@ -184,9 +181,6 @@ def render_exception(self, item: ItemData) -> t.Iterable[str]:
184181

185182
def render_class(self, item: ItemData) -> t.Iterable[str]:
186183
"""Create the content for a class."""
187-
if self.is_hidden(item):
188-
return
189-
190184
short_name = item["full_name"].split(".")[-1]
191185
constructor = self.get_item(f"{item['full_name']}.__init__")
192186
sig = short_name
@@ -240,9 +234,6 @@ def render_class(self, item: ItemData) -> t.Iterable[str]:
240234

241235
def render_property(self, item: ItemData) -> t.Iterable[str]:
242236
"""Create the content for a property."""
243-
if self.is_hidden(item):
244-
return
245-
246237
short_name = item["full_name"].split(".")[-1]
247238
yield f".. py:property:: {short_name}"
248239
yield f" :canonical: {item['full_name']}"
@@ -261,9 +252,6 @@ def render_property(self, item: ItemData) -> t.Iterable[str]:
261252

262253
def render_method(self, item: ItemData) -> t.Iterable[str]:
263254
"""Create the content for a method."""
264-
if self.is_hidden(item):
265-
return
266-
267255
short_name = item["full_name"].split(".")[-1]
268256
show_annotations = self.show_annotations(item)
269257
sig = f"{short_name}({self.format_args(item['args'], show_annotations, ignore_self='self')})"
@@ -292,9 +280,6 @@ def render_attribute(self, item: ItemData) -> t.Iterable[str]:
292280

293281
def render_data(self, item: ItemData) -> t.Iterable[str]:
294282
"""Create the content for a data item."""
295-
if self.is_hidden(item):
296-
return
297-
298283
short_name = item["full_name"].split(".")[-1]
299284
yield f".. py:{item['type']}:: {short_name}"
300285
yield f" :canonical: {item['full_name']}"

0 commit comments

Comments
 (0)