Skip to content

Instantly share code, notes, and snippets.

@jorisvandenbossche
Created July 18, 2015 18:11
Show Gist options
  • Save jorisvandenbossche/fca564257920e166a294 to your computer and use it in GitHub Desktop.
Save jorisvandenbossche/fca564257920e166a294 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Python script for building documentation.
To build the docs you must have all optional dependencies for pandas
installed. See the installation instructions for a list of these.
Note: currently latex builds do not work because of table formats that are not
supported in the latex generation.
Usage
-----
python make.py clean
python make.py html
python build-docstring.py method pandas DataFrame.join
"""
from __future__ import print_function
import glob
import os
import shutil
import sys
import sphinx
os.environ['PYTHONPATH'] = '..'
SPHINX_BUILD = 'sphinxbuild'
import webbrowser
def _write_temp_file(classtype, module, function):
s = """{1}.{2}
=================================
.. currentmodule:: {1}
.. auto{0}:: {2}""".format(classtype, module, function)
with open("source/temp.rst", 'w') as f:
f.write(s)
def _remove_temp_file():
os.remove("source/temp.rst")
def build_docstring():
if os.system('sphinx-build -P -b html -d build/doctrees -w log.out '
'source build/html source/temp.rst'):
raise SystemExit("Building docstring failed.")
def open_html():
new = 2 # open in a new tab, if possible
# open an HTML file on my own (Windows) computer
url = "file://" + os.getcwd() + "/build/html/temp.html"
#webbrowser.open(url,new=new)
webbrowser.WindowsDefault().open_new_tab(url)
#funcd = {
# 'docstring': html
#}
#ftype = sys.argv[1]
#func = funcd.get(ftype)
#if func is None:
# raise SystemExit('Do not know how to handle %s; valid args are %s' % (
# arg, list(funcd.keys())))
classtype = sys.argv[1]
module = sys.argv[2]
function = sys.argv[3]
_write_temp_file(classtype, module, function)
build_docstring()
#_remove_temp_file()
#open_html()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment