Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/fake_bpy_module/analyzer/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,27 @@ def run(self) -> list[BaseClassListNode]:
return [base_class_list_node]


class DetailsDirective(rst.Directive):
required_arguments = 0
optional_arguments = 1
final_argument_whitespace = True
has_content = True

def run(self) -> list[FunctionNode]:
# `.. details::` used in Blender docs to denote a section
# with dunder methods.
# See "Special Methods" in
# https://docs.blender.org/api/5.2/bmesh.types.html#bmesh.types.BMDeformVert
# Skipped for now: it's currently undecided how to correctly merge
# conflicts between fake-bpy mod.rst overrides and upstream dunder
# methods, since the two use different approaches:
# fake-bpy: `bpy_prop_collection.__getitem__`->`_GenericType1`
# upstream: `bpy_prop_collection.__getitem__`->`bpy_struct`, then
# reimplements e.g. `BlendDataObjects.__getitem__`->`Object`
# in stubs (not present in docs)
return []


def register_directives() -> None:
rst.directives.register_directive("module", ModuleDirective)
rst.directives.register_directive("currentmodule", ModuleDirective)
Expand All @@ -715,5 +736,6 @@ def register_directives() -> None:
rst.directives.register_directive("deprecated", DocumentDirective)

rst.directives.register_directive("include", NopDirective)
rst.directives.register_directive("details", DetailsDirective)

rst.directives.register_directive("mod-type", ModTypeDirective)
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,16 @@ def test_generic_types(self) -> None:
self.assertEqual(len(documents), len(rst_files))
for doc, expect in zip(documents, expect_files, strict=True):
self.compare_with_file_contents(doc.pformat(), expect)

def test_details_directive(self) -> None:
rst_files = ["details_directive.rst"]
expect_files = ["details_directive.xml"]
rst_files = [f"{self.data_dir}/input/{f}" for f in rst_files]
expect_files = [f"{self.data_dir}/expect/{f}" for f in expect_files]

analyzer = BaseAnalyzer()
documents = analyzer.analyze(rst_files)

self.assertEqual(len(documents), len(rst_files))
for doc, expect in zip(documents, expect_files, strict=True):
self.compare_with_file_contents(doc.pformat(), expect)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<document source="<string>">
<source-filename>
details_directive.rst
<module>
<name>
module_1
<description>
<class>
<name>
ClassA
<description>
ClassA description
<base-class-list>
<attribute-list>
<function-list>
<function function_type="method">
<name>
method_1
<description>
method_1 description
<argument-list>
<return>
<description>
method_1 return description
<data-type-list>
<data-type>
method_1 return type
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. module:: module_1

.. class:: ClassA

ClassA description

.. method:: method_1()

method_1 description

:return: method_1 return description
:rtype: method_1 return type

.. details:: Special Methods

.. method:: __eq__(other)

:param other: The other operand.
:type other: object
:rtype: bool

.. method:: __hash__()

:rtype: int
Loading