Skip to content

Commit 540e69e

Browse files
committed
move API docs to docstrings and build with sphinx
1 parent fcf02a6 commit 540e69e

File tree

11 files changed

+908
-527
lines changed

11 files changed

+908
-527
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/build
22
/dist
33
/src/liblo.c
4+
/doc/build
45
liblo*.so
56
pyliblo.egg-info
67
wheel-*.egg

doc/API.html

-276
This file was deleted.

doc/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SPHINXOPTS =
2+
SPHINXBUILD = sphinx-build
3+
BUILDDIR = build
4+
5+
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
6+
7+
.PHONY: clean html
8+
9+
html:
10+
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
11+
12+
clean:
13+
-rm -rf $(BUILDDIR)/*

doc/conf.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
import sys, os
4+
5+
sys.path.insert(0, os.path.abspath('..'))
6+
7+
#extensions = ['sphinx.ext.autodoc', 'sphinxcontrib.fulltoc']
8+
extensions = ['sphinx.ext.autodoc']
9+
10+
templates_path = ['templates']
11+
html_theme_path = ['theme']
12+
exclude_patterns = ['build']
13+
14+
source_suffix = '.rst'
15+
master_doc = 'index'
16+
17+
project = u'pyliblo'
18+
copyright = u'2007-2014, Dominic Sacré'
19+
version = '0.10.0'
20+
release = ''
21+
22+
html_theme = 'nasophon'
23+
html_copy_source = False
24+
pygments_style = 'sphinx'
25+
26+
add_module_names = False
27+
autodoc_member_order = 'bysource'
28+
autodoc_default_flags = ['members', 'undoc-members']
29+
30+
31+
from sphinx.ext.autodoc import py_ext_sig_re
32+
from sphinx.util.docstrings import prepare_docstring
33+
from sphinx.domains.python import PyClassmember, PyObject, py_sig_re
34+
35+
36+
def process_docstring(app, what, name, obj, options, lines):
37+
"""
38+
Remove leading function signatures from docstring.
39+
"""
40+
while len(lines) and py_ext_sig_re.match(lines[0]) is not None:
41+
del lines[0]
42+
43+
def process_signature(app, what, name, obj,
44+
options, signature, return_annotation):
45+
"""
46+
Replace function signature with those specified in the docstring.
47+
"""
48+
if hasattr(obj, '__doc__') and obj.__doc__ is not None:
49+
lines = prepare_docstring(obj.__doc__)
50+
siglines = []
51+
52+
for line in lines:
53+
if py_ext_sig_re.match(line) is not None:
54+
siglines.append(line)
55+
else:
56+
break
57+
58+
if len(siglines):
59+
siglines[0] = siglines[0][siglines[0].index('('):]
60+
return ('\n'.join(siglines), None)
61+
62+
return (signature, return_annotation)
63+
64+
65+
# monkey-patch PyClassmember.handle_signature() to replace __init__
66+
# with the class name.
67+
handle_signature_orig = PyClassmember.handle_signature
68+
def handle_signature(self, sig, signode):
69+
if '__init__' in sig:
70+
m = py_sig_re.match(sig)
71+
name_prefix, name, arglist, retann = m.groups()
72+
sig = sig.replace('__init__', name_prefix[:-1])
73+
return handle_signature_orig(self, sig, signode)
74+
PyClassmember.handle_signature = handle_signature
75+
76+
77+
# prevent exception fields from collapsing
78+
PyObject.doc_field_types[2].can_collapse = False
79+
80+
81+
def setup(app):
82+
app.connect('autodoc-process-docstring', process_docstring)
83+
app.connect('autodoc-process-signature', process_signature)

0 commit comments

Comments
 (0)