16
16
import shutil
17
17
import subprocess
18
18
import argparse
19
+ import tempfile
19
20
from contextlib import contextmanager
20
21
import jinja2
21
22
@@ -123,14 +124,18 @@ def _run_os(*args):
123
124
"""
124
125
subprocess .check_call (args , stderr = subprocess .STDOUT )
125
126
126
- def _sphinx_build (self , kind ):
127
+ def _sphinx_build (self , kind , source_path = None , build_path = None ):
127
128
"""Call sphinx to build documentation.
128
129
129
130
Attribute `num_jobs` from the class is used.
130
131
131
132
Parameters
132
133
----------
133
134
kind : {'html', 'latex'}
135
+ source_path: str or None
136
+ Directory with the sources to build
137
+ build_path: str or None
138
+ Target directory where built files will be generated
134
139
135
140
Examples
136
141
--------
@@ -139,13 +144,18 @@ def _sphinx_build(self, kind):
139
144
if kind not in ('html' , 'latex' ):
140
145
raise ValueError ('kind must be html or latex, not {}' .format (kind ))
141
146
147
+ if source_path is None :
148
+ source_path = SOURCE_PATH
149
+ if build_path is None :
150
+ build_path = os .path .join (BUILD_PATH , kind )
151
+
142
152
self ._run_os ('sphinx-build' ,
143
153
'-j{}' .format (self .num_jobs ),
144
154
'-b{}' .format (kind ),
145
155
'-d{}' .format (os .path .join (BUILD_PATH ,
146
156
'doctrees' )),
147
- SOURCE_PATH ,
148
- os . path . join ( BUILD_PATH , kind ) )
157
+ source_path ,
158
+ build_path )
149
159
150
160
def html (self ):
151
161
"""Build HTML documentation."""
@@ -199,6 +209,42 @@ def zip_html(self):
199
209
'-q' ,
200
210
* fnames )
201
211
212
+ def html_single (self , method = 'pandas.DataFrame.reset_index' ):
213
+ # TODO: call apidoc?
214
+ temp_dir = tempfile .mkdtemp ()
215
+ os .mkdir (os .path .join (temp_dir , 'source' ))
216
+ os .mkdir (os .path .join (temp_dir , 'build' ))
217
+ symlinks = ('sphinxext' ,
218
+ '_templates' ,
219
+ os .path .join ('source' , '_static' ),
220
+ os .path .join ('source' , 'themes' ))
221
+ for dirname in symlinks :
222
+ os .symlink (os .path .join (DOC_PATH , dirname ),
223
+ os .path .join (temp_dir , dirname ),
224
+ target_is_directory = True )
225
+ os .symlink (os .path .join (DOC_PATH , 'source' , 'conf.py' ),
226
+ os .path .join (temp_dir , 'source' , 'conf.py' ),
227
+ target_is_directory = False )
228
+ os .symlink (os .path .join (DOC_PATH , 'source' , 'generated' ,
229
+ '{}.rst' .format (method )),
230
+ os .path .join (temp_dir , 'source' , '{}.rst' .format (method )),
231
+ target_is_directory = False )
232
+
233
+ idx_content = '.. toctree::\n \t :maxdepth: 2\n \t \n \t {}' .format (method )
234
+ with open (os .path .join (temp_dir , 'source' , 'index.rst' ), 'w' ) as f :
235
+ f .write (idx_content )
236
+
237
+ self ._sphinx_build ('html' ,
238
+ os .path .join (temp_dir , 'source' ),
239
+ os .path .join (temp_dir , 'build' ))
240
+
241
+ os .makedirs (os .path .join (BUILD_PATH , 'html' , 'generated' ))
242
+ shutil .copy (
243
+ os .path .join (temp_dir , 'build' , '{}.html' .format (method )),
244
+ os .path .join (BUILD_PATH , 'html' , 'generated' ,
245
+ '{}.html' .format (method )))
246
+ shutil .rmtree (temp_dir )
247
+
202
248
203
249
def main ():
204
250
cmds = [method for method in dir (DocBuilder ) if not method .startswith ('_' )]
0 commit comments