23
23
24
24
logger = logging .getLogger (__name__ )
25
25
26
-
27
- sys .path .append ('.' )
28
- from bootstrap_html_translator import BootstrapHTML5Translator
26
+ import pandas_sphinx_theme
29
27
30
28
31
29
# -----------------------------------------------------------------------------
@@ -109,144 +107,86 @@ def run(self):
109
107
# -----------------------------------------------------------------------------
110
108
# Sphinx monkeypatch
111
109
112
- from sphinx .environment .adapters .toctree import process_only_nodes
113
- from docutils import nodes
114
- from sphinx import addnodes
115
-
116
-
117
- def get_toc_for (self , docname , builder ):
118
- # type: (str, Builder) -> nodes.Node
119
- """Return a TOC nodetree -- for use on the same page only!"""
120
- tocdepth = self .env .metadata [docname ].get ('tocdepth' , 0 )
121
- try :
122
- toc = self .env .tocs [docname ].deepcopy ()
123
- self ._toctree_prune (toc , 2 , tocdepth )
124
- except KeyError :
125
- # the document does not exist anymore: return a dummy node that
126
- # renders to nothing
127
- return nodes .paragraph ()
128
- process_only_nodes (toc , builder .tags )
129
- for node in toc .traverse (nodes .reference ):
130
- node ['refuri' ] = node ['anchorname' ] or '#'
131
-
132
- # tag toc with attributes
133
- toc .attributes ['classes' ].append ('section-nav' )
134
-
135
- def tag_childs (bullet_list , level ):
136
- for sub in bullet_list .children :
137
- if getattr (sub , 'tagname' , '' ) == 'list_item' :
138
- sub .attributes ['classes' ].extend (['toc-entry' , 'toc-h{}' .format (level )])
139
- for sub2 in sub .children :
140
- if getattr (sub2 , 'tagname' , '' ) == 'bullet_list' :
141
- tag_childs (sub2 , level + 1 )
142
-
143
- tag_childs (toc , 1 )
144
-
145
- return toc
146
-
147
- def get_toctree_for (self , docname , builder , collapse , ** kwds ):
148
- # type: (str, Builder, bool, Any) -> nodes.Element
149
- """Return the global TOC nodetree."""
150
- #import pdb; pdb.set_trace()
151
- doctree = self .env .get_doctree (self .env .config .master_doc )
152
- toctrees = [] # type: List[nodes.Element]
153
- if 'includehidden' not in kwds :
154
- kwds ['includehidden' ] = True
155
- if 'maxdepth' not in kwds :
156
- kwds ['maxdepth' ] = 0
157
- kwds ['collapse' ] = collapse
158
- mindepth = kwds .pop ('mindepth' , False )
159
- for toctreenode in doctree .traverse (addnodes .toctree ):
160
- toctree = self .resolve (docname , builder , toctreenode , prune = True , ** kwds )
161
- if toctree :
162
- toctrees .append (toctree )
163
- if not toctrees :
164
- return None
165
- result = toctrees [0 ]
166
- for toctree in toctrees [1 :]:
167
- result .extend (toctree .children )
168
- if mindepth and docname not in ('index' , 'genindex' , 'search' ):
169
- #import pdb; pdb.set_trace()
170
- result = get_current_section_toctree (result )
171
- return result
172
-
173
-
174
- def get_current_section_toctree (toctree ):
175
- actual_toctree = toctree [0 ]
176
- for subtoc in actual_toctree .children :
177
- if 'current' in subtoc .attributes ['classes' ]:
178
- newtoc = subtoc .children [1 ]
179
- break
180
- else :
181
- newtoc = actual_toctree
182
- toctree [0 ] = newtoc
183
- toctree [0 ].attributes ['classes' ].extend (['nav' , 'bd-sidenav' , 'active' ])
184
- #import pdb; pdb.set_trace()
185
- return toctree
186
-
187
-
188
- import sphinx .environment .adapters .toctree
189
- sphinx .environment .adapters .toctree .TocTree .get_toc_for = get_toc_for
190
- sphinx .environment .adapters .toctree .TocTree .get_toctree_for = get_toctree_for
191
-
192
-
193
- def convert_docutils_node (list_item ):
194
- if not list_item .children :
195
- return None
196
- reference = list_item .children [0 ].children [0 ]
197
- title = reference .astext ()
198
- url = reference .attributes ['refuri' ]
199
- active = 'current' in list_item .attributes ['classes' ]
200
-
201
- nav = {}
202
- nav ['title' ] = title
203
- nav ['url' ] = url
204
- nav ['children' ] = []
205
- nav ['active' ] = active
206
-
207
- if len (list_item .children ) > 1 :
208
- for child_item in list_item .children [1 ].children :
209
- child_nav = convert_docutils_node (child_item )
210
- if child_nav is not None :
211
- nav ['children' ].append (child_nav )
212
-
213
- return nav
214
-
215
-
216
- def update_page_context (self , pagename , templatename , ctx , event_arg ):
217
- from sphinx .environment .adapters .toctree import TocTree
218
-
219
- def get_nav_object (** kwds ):
220
- toctree = TocTree (self .env ).get_toctree_for (
221
- pagename , self , collapse = True , ** kwds )
222
-
223
- nav = []
224
- for child in toctree .children [0 ].children :
225
- child_nav = convert_docutils_node (child )
226
- nav .append (child_nav )
227
-
228
- return nav
229
-
230
- def get_page_toc_object ():
231
- self_toc = TocTree (self .env ).get_toc_for (pagename , self )
232
- toc = self .render_partial (self_toc )['fragment' ]
233
-
234
- try :
235
- #import pdb; pdb.set_trace()
236
- nav = convert_docutils_node (self_toc .children [0 ])
237
- #import pdb; pdb.set_trace()
238
- return nav
239
- except :
240
- return {}
241
-
242
- #import pdb; pdb.set_trace()
243
- ctx ['get_nav_object' ] = get_nav_object
244
- ctx ['get_page_toc_object' ] = get_page_toc_object
245
- return None
246
-
110
+ # from sphinx.environment.adapters.toctree import process_only_nodes
111
+ # from docutils import nodes
112
+ # from sphinx import addnodes
113
+
114
+
115
+ # def get_toc_for(self, docname, builder):
116
+ # # type: (str, Builder) -> nodes.Node
117
+ # """Return a TOC nodetree -- for use on the same page only!"""
118
+ # tocdepth = self.env.metadata[docname].get('tocdepth', 0)
119
+ # try:
120
+ # toc = self.env.tocs[docname].deepcopy()
121
+ # self._toctree_prune(toc, 2, tocdepth)
122
+ # except KeyError:
123
+ # # the document does not exist anymore: return a dummy node that
124
+ # # renders to nothing
125
+ # return nodes.paragraph()
126
+ # process_only_nodes(toc, builder.tags)
127
+ # for node in toc.traverse(nodes.reference):
128
+ # node['refuri'] = node['anchorname'] or '#'
129
+
130
+ # # tag toc with attributes
131
+ # toc.attributes['classes'].append('section-nav')
132
+
133
+ # def tag_childs(bullet_list, level):
134
+ # for sub in bullet_list.children:
135
+ # if getattr(sub, 'tagname', '') == 'list_item':
136
+ # sub.attributes['classes'].extend(['toc-entry', 'toc-h{}'.format(level)])
137
+ # for sub2 in sub.children:
138
+ # if getattr(sub2, 'tagname', '') == 'bullet_list':
139
+ # tag_childs(sub2, level + 1)
140
+
141
+ # tag_childs(toc, 1)
142
+
143
+ # return toc
144
+
145
+ # def get_toctree_for(self, docname, builder, collapse, **kwds):
146
+ # # type: (str, Builder, bool, Any) -> nodes.Element
147
+ # """Return the global TOC nodetree."""
148
+ # #import pdb; pdb.set_trace()
149
+ # doctree = self.env.get_doctree(self.env.config.master_doc)
150
+ # toctrees = [] # type: List[nodes.Element]
151
+ # if 'includehidden' not in kwds:
152
+ # kwds['includehidden'] = True
153
+ # if 'maxdepth' not in kwds:
154
+ # kwds['maxdepth'] = 0
155
+ # kwds['collapse'] = collapse
156
+ # mindepth = kwds.pop('mindepth', False)
157
+ # for toctreenode in doctree.traverse(addnodes.toctree):
158
+ # toctree = self.resolve(docname, builder, toctreenode, prune=True, **kwds)
159
+ # if toctree:
160
+ # toctrees.append(toctree)
161
+ # if not toctrees:
162
+ # return None
163
+ # result = toctrees[0]
164
+ # for toctree in toctrees[1:]:
165
+ # result.extend(toctree.children)
166
+ # if mindepth and docname not in ('index', 'genindex', 'search'):
167
+ # #import pdb; pdb.set_trace()
168
+ # result = get_current_section_toctree(result)
169
+ # return result
170
+
171
+
172
+ # def get_current_section_toctree(toctree):
173
+ # actual_toctree = toctree[0]
174
+ # for subtoc in actual_toctree.children:
175
+ # if 'current' in subtoc.attributes['classes']:
176
+ # newtoc = subtoc.children[1]
177
+ # break
178
+ # else:
179
+ # newtoc = actual_toctree
180
+ # toctree[0] = newtoc
181
+ # toctree[0].attributes['classes'].extend(['nav', 'bd-sidenav', 'active'])
182
+ # #import pdb; pdb.set_trace()
183
+ # return toctree
184
+
185
+
186
+ # import sphinx.environment.adapters.toctree
187
+ # sphinx.environment.adapters.toctree.TocTree.get_toc_for = get_toc_for
188
+ # sphinx.environment.adapters.toctree.TocTree.get_toctree_for = get_toctree_for
247
189
248
- import sphinx .builders .html
249
- sphinx .builders .html .StandaloneHTMLBuilder .update_page_context = update_page_context
250
190
251
191
# -----------------------------------------------------------------------------
252
192
@@ -420,7 +360,7 @@ def get_page_toc_object():
420
360
421
361
# The theme to use for HTML and HTML Help pages. Major themes that come with
422
362
# Sphinx are currently 'default' and 'sphinxdoc'.
423
- html_theme = 'bootstrap_docs_theme '
363
+ html_theme = 'pandas_sphinx_theme '
424
364
425
365
# The style sheet to use for HTML and HTML Help pages. A file of that name
426
366
# must exist either in Sphinx' static/ path, or in one of the custom paths
@@ -433,7 +373,7 @@ def get_page_toc_object():
433
373
# html_theme_options = {}
434
374
435
375
# Add any paths that contain custom themes here, relative to this directory.
436
- html_theme_path = ['_themes' ]
376
+ # html_theme_path = ['_themes']
437
377
438
378
# The name for this set of Sphinx documents. If None, it defaults to
439
379
# "<project> v<release> documentation".
@@ -989,4 +929,3 @@ def setup(app):
989
929
app .add_autodocumenter (AccessorMethodDocumenter )
990
930
app .add_autodocumenter (AccessorCallableDocumenter )
991
931
app .add_directive ('autosummary' , PandasAutosummary )
992
- app .set_translator ('html' , BootstrapHTML5Translator )
0 commit comments