Commit c53502a2 authored by Dave Reisner's avatar Dave Reisner

Play nicely with py3k for building docs

Previously, mkapiref.py required python2.6, as it used format strings,
but continued to use print as a keyword, not a function. But, since 2.6
is implicitly made a requirement, we can also count on print being
available as a function.

This change adds python2.6 as a soft requirement during ./configure,
and converts all print keywords to statements. There's no need to do
anything about the actual building of the doc since sphinx-build can
run under python2 and python3.

The net result is that it no longer matters whether 'python' points to
python2 or python3 (see PEP394), because both will be able to run
mkapiref.py successfully.
parent 41ac4578
......@@ -76,6 +76,7 @@ AC_PROG_LN_S
AC_PROG_MAKE_SET
AM_PROG_CC_C_O
PKG_PROG_PKG_CONFIG([0.20])
AM_PATH_PYTHON([2.6],, [:])
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
......
......@@ -61,7 +61,7 @@ help:
apiref.rst: $(top_builddir)/lib/includes/nghttp2/nghttp2ver.h \
$(top_builddir)/lib/includes/nghttp2/nghttp2.h
$(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
$(PYTHON) $(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
clean:
-rm apiref.rst
......
......@@ -23,6 +23,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Generates API reference from C source code.
from __future__ import print_function # At least python 2.6 is required
import re, sys, argparse
class FunctionDoc:
......@@ -32,10 +33,10 @@ class FunctionDoc:
self.domain = domain
def write(self, out):
print '''.. {}:: {}'''.format(self.domain, self.name)
print ''
print('''.. {}:: {}'''.format(self.domain, self.name))
print('')
for line in self.content:
print ' {}'.format(line)
print(' {}'.format(line))
class StructDoc:
def __init__(self, name, content, members, member_domain):
......@@ -46,17 +47,17 @@ class StructDoc:
def write(self, out):
if self.name:
print '''.. type:: {}'''.format(self.name)
print ''
print('''.. type:: {}'''.format(self.name))
print('')
for line in self.content:
print ' {}'.format(line)
print ''
print(' {}'.format(line))
print('')
for name, content in self.members:
print ''' .. {}:: {}'''.format(self.member_domain, name)
print ''
print(''' .. {}:: {}'''.format(self.member_domain, name))
print('')
for line in content:
print ''' {}'''.format(line)
print ''
print(''' {}'''.format(line))
print('')
class MacroDoc:
def __init__(self, name, content):
......@@ -64,10 +65,10 @@ class MacroDoc:
self.content = content
def write(self, out):
print '''.. macro:: {}'''.format(self.name)
print ''
print('''.. macro:: {}'''.format(self.name))
print('')
for line in self.content:
print ' {}'.format(line)
print(' {}'.format(line))
def make_api_ref(infiles):
macros = []
......@@ -99,12 +100,12 @@ def make_api_ref(infiles):
for title, docs in alldocs:
if not docs:
continue
print title
print '-'*len(title)
print(title)
print('-'*len(title))
for doc in docs:
doc.write(sys.stdout)
print ''
print ''
print('')
print('')
def process_macro(infile):
content = read_content(infile)
......@@ -204,6 +205,6 @@ if __name__ == '__main__':
help='source file')
args = parser.parse_args()
if args.header:
print args.header.read()
print(args.header.read())
for infile in args.files:
make_api_ref(args.files)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment