forked from neomonkeus/pyffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epydoc-sphinx.patch
161 lines (158 loc) · 5.68 KB
/
epydoc-sphinx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Index: src/epydoc/markup/restructuredtext.py
===================================================================
--- src/epydoc/markup/restructuredtext.py (revision 1812)
+++ src/epydoc/markup/restructuredtext.py (working copy)
@@ -729,6 +729,12 @@
HTMLTranslator.visit_emphasis(self, node)
+ def unknown_visit(self, node):
+ pass
+
+ def unknown_departure(self, node):
+ pass
+
def python_code_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
"""
@@ -946,3 +952,143 @@
docs = [context]
return call_graph(docs, docindex, linker, context, **options)
+# register sphinx roles and directives
+import epydoc.docwriter.xlink
+import docutils.parsers.rst.directives.misc
+import docutils.parsers.rst.directives.admonitions
+from docutils.parsers.rst import Directive
+
+# links
+#epydoc.docwriter.xlink.register_api('mod')
+#epydoc.docwriter.xlink.create_api_role('mod', False)
+#epydoc.docwriter.xlink.register_api('class')
+#epydoc.docwriter.xlink.create_api_role('class', False)
+#epydoc.docwriter.xlink.register_api('attr')
+#epydoc.docwriter.xlink.create_api_role('attr', False)
+#epydoc.docwriter.xlink.register_api('meth')
+#epydoc.docwriter.xlink.create_api_role('meth', False)
+
+# markup
+def reference_role(name, rawtext, text, lineno, inliner,
+ options={}, content=[]):
+ # sphinx extension for references with just last component
+ # not sure how to do this with epydoc...
+ if text.startswith('~'):
+ text = text[1:]
+ #node = docutils.nodes.literal(rawtext, text, **options)
+ #url = ???
+ #if url is not None:
+ # node = docutils.nodes.reference(rawtext, '', refuri=url, **options)
+ node = docutils.nodes.title_reference(rawtext, text, **options)
+ node.attributes['classes'].append('title_reference')
+ return [node], []
+def literal_role(name, rawtext, text, lineno, inliner,
+ options={}, content=[]):
+ text = docutils.utils.unescape(text)
+ node = docutils.nodes.literal(rawtext, text, **options)
+ node.attributes['classes'].append('literal')
+ return [node], []
+def strong_role(name, rawtext, text, lineno, inliner,
+ options={}, content=[]):
+ text = docutils.utils.unescape(text)
+ node = docutils.nodes.strong(rawtext, text, **options)
+ node.attributes['classes'].append('strong')
+ return [node], []
+roles.register_local_role('mod', reference_role)
+roles.register_local_role('class', reference_role)
+roles.register_local_role('attr', reference_role)
+roles.register_local_role('meth', reference_role)
+roles.register_local_role('file', literal_role)
+roles.register_local_role('envvar', strong_role)
+
+# advanced stuff that we will ignore
+
+class TocTree(Directive):
+ """
+ Directive to notify Sphinx about the hierarchical structure of the docs,
+ and to include a table-of-contents like tree in the current document.
+ """
+ has_content = True
+ required_arguments = 0
+ optional_arguments = 0
+ final_argument_whitespace = False
+ option_spec = {
+ 'maxdepth': int,
+ 'glob': directives.flag,
+ 'hidden': directives.flag,
+ 'numbered': directives.flag,
+ }
+ def run(self):
+ return []
+
+directives.register_directive('toctree', TocTree)
+
+class LiteralInclude(docutils.parsers.rst.directives.misc.Include):
+ """
+ Like ``.. include:: :literal:``, but only warns if the include file is
+ not found, and does not raise errors. Also has several options for
+ selecting what to include.
+ """
+ required_arguments = 1
+ optional_arguments = 0
+ option_spec = {
+ 'linenos': directives.flag,
+ 'language': directives.unchanged_required,
+ 'encoding': directives.encoding,
+ 'pyobject': directives.unchanged_required,
+ 'lines': directives.unchanged_required,
+ 'start-after': directives.unchanged_required,
+ 'end-before': directives.unchanged_required,
+ }
+ def run(self):
+ self.options['literal'] = True
+ return docutils.parsers.rst.directives.misc.Include.run(self)
+
+directives.register_directive('literalinclude', LiteralInclude)
+
+# XXX epydoc just keeps complaining about this one...
+directives.register_directive(
+ 'warning', docutils.parsers.rst.directives.admonitions.Warning)
+
+class DefDict(dict):
+ """A dict that returns a default on nonexisting keys."""
+ def __init__(self, default):
+ dict.__init__(self)
+ self.default = default
+ def __getitem__(self, key):
+ try:
+ return dict.__getitem__(self, key)
+ except KeyError:
+ return self.default
+ def __nonzero__(self):
+ # docutils check "if option_spec"
+ return True
+
+identity = lambda x: x
+
+class StubDirective(Directive):
+ """
+ Pretty table containing short signatures and summaries of functions etc.
+ autosummary also generates a (hidden) toctree:: node.
+ """
+ has_content = True
+ required_arguments = 1
+ optional_arguments = 0
+ final_argument_whitespace = True
+ # allow any options to be passed; the options are parsed further
+ # by the selected Documenter
+ option_spec = DefDict(identity)
+
+ def run(self):
+ return []
+
+directives.register_directive('automodule', StubDirective)
+directives.register_directive('autoattribute', StubDirective)
+directives.register_directive('autoclass', StubDirective)
+directives.register_directive('autofunction', StubDirective)
+directives.register_directive('todo', StubDirective)
+
+# XXX just importing these does not work unfortunately
+#import sphinx.roles
+#import sphinx.directives
+#import sphinx.addnodes