Skip to content

Commit 5b4cc3b

Browse files
Implementing single api doc building using temp directory
1 parent ca27ee9 commit 5b4cc3b

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

doc/make.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import shutil
1717
import subprocess
1818
import argparse
19+
import tempfile
1920
from contextlib import contextmanager
2021
import jinja2
2122

@@ -123,14 +124,18 @@ def _run_os(*args):
123124
"""
124125
subprocess.check_call(args, stderr=subprocess.STDOUT)
125126

126-
def _sphinx_build(self, kind):
127+
def _sphinx_build(self, kind, source_path=None, build_path=None):
127128
"""Call sphinx to build documentation.
128129
129130
Attribute `num_jobs` from the class is used.
130131
131132
Parameters
132133
----------
133134
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
134139
135140
Examples
136141
--------
@@ -139,13 +144,18 @@ def _sphinx_build(self, kind):
139144
if kind not in ('html', 'latex'):
140145
raise ValueError('kind must be html or latex, not {}'.format(kind))
141146

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+
142152
self._run_os('sphinx-build',
143153
'-j{}'.format(self.num_jobs),
144154
'-b{}'.format(kind),
145155
'-d{}'.format(os.path.join(BUILD_PATH,
146156
'doctrees')),
147-
SOURCE_PATH,
148-
os.path.join(BUILD_PATH, kind))
157+
source_path,
158+
build_path)
149159

150160
def html(self):
151161
"""Build HTML documentation."""
@@ -199,6 +209,42 @@ def zip_html(self):
199209
'-q',
200210
*fnames)
201211

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+
202248

203249
def main():
204250
cmds = [method for method in dir(DocBuilder) if not method.startswith('_')]

0 commit comments

Comments
 (0)