Skip to content

Commit bb5c8ad

Browse files
committed
Update: add handling for .. details:: section
1 parent a79f9e9 commit bb5c8ad

4 files changed

Lines changed: 110 additions & 0 deletions

File tree

src/fake_bpy_module/analyzer/directives.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,22 @@ def run(self) -> list[BaseClassListNode]:
691691
return [base_class_list_node]
692692

693693

694+
class DetailsDirective(rst.Directive):
695+
required_arguments = 0
696+
optional_arguments = 1
697+
final_argument_whitespace = True
698+
has_content = True
699+
700+
def run(self) -> list[nodes.Node]:
701+
container = nodes.Element()
702+
self.state.nested_parse(self.content, self.content_offset, container)
703+
children = list(container.children)
704+
container.children = []
705+
for child in children:
706+
child.parent = None
707+
return children
708+
709+
694710
def register_directives() -> None:
695711
rst.directives.register_directive("module", ModuleDirective)
696712
rst.directives.register_directive("currentmodule", ModuleDirective)
@@ -715,5 +731,6 @@ def register_directives() -> None:
715731
rst.directives.register_directive("deprecated", DocumentDirective)
716732

717733
rst.directives.register_directive("include", NopDirective)
734+
rst.directives.register_directive("details", DetailsDirective)
718735

719736
rst.directives.register_directive("mod-type", ModTypeDirective)

tests/python/fake_bpy_module_test/fake_bpy_module_test/analyzer_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,16 @@ def test_generic_types(self) -> None:
350350
self.assertEqual(len(documents), len(rst_files))
351351
for doc, expect in zip(documents, expect_files, strict=True):
352352
self.compare_with_file_contents(doc.pformat(), expect)
353+
354+
def test_details_directive(self) -> None:
355+
rst_files = ["details_directive.rst"]
356+
expect_files = ["details_directive.xml"]
357+
rst_files = [f"{self.data_dir}/input/{f}" for f in rst_files]
358+
expect_files = [f"{self.data_dir}/expect/{f}" for f in expect_files]
359+
360+
analyzer = BaseAnalyzer()
361+
documents = analyzer.analyze(rst_files)
362+
363+
self.assertEqual(len(documents), len(rst_files))
364+
for doc, expect in zip(documents, expect_files, strict=True):
365+
self.compare_with_file_contents(doc.pformat(), expect)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<document source="<string>">
2+
<source-filename>
3+
details_directive.rst
4+
<module>
5+
<name>
6+
module_1
7+
<description>
8+
<class>
9+
<name>
10+
ClassA
11+
<description>
12+
ClassA description
13+
<base-class-list>
14+
<attribute-list>
15+
<function-list>
16+
<function function_type="method">
17+
<name>
18+
method_1
19+
<description>
20+
method_1 description
21+
<argument-list>
22+
<return>
23+
<description>
24+
method_1 return description
25+
<data-type-list>
26+
<data-type>
27+
method_1 return type
28+
<function function_type="method">
29+
<name>
30+
__eq__
31+
<description>
32+
<argument-list>
33+
<argument argument_type="arg">
34+
<name>
35+
other
36+
<description>
37+
The other operand.
38+
<default-value>
39+
<data-type-list>
40+
<data-type>
41+
object
42+
<return>
43+
<description>
44+
<data-type-list>
45+
<data-type>
46+
bool
47+
<function function_type="method">
48+
<name>
49+
__hash__
50+
<description>
51+
<argument-list>
52+
<return>
53+
<description>
54+
<data-type-list>
55+
<data-type>
56+
int
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. module:: module_1
2+
3+
.. class:: ClassA
4+
5+
ClassA description
6+
7+
.. method:: method_1()
8+
9+
method_1 description
10+
11+
:return: method_1 return description
12+
:rtype: method_1 return type
13+
14+
.. details:: Special Methods
15+
16+
.. method:: __eq__(other)
17+
18+
:param other: The other operand.
19+
:type other: object
20+
:rtype: bool
21+
22+
.. method:: __hash__()
23+
24+
:rtype: int

0 commit comments

Comments
 (0)