From c53502a261ea8d9aff473e0b44d445b68634788a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 7 Sep 2013 09:48:36 -0400 Subject: [PATCH] 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. --- configure.ac | 1 + doc/Makefile.am | 2 +- doc/mkapiref.py | 39 ++++++++++++++++++++------------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 01d8c6e7..c78f03ed 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/doc/Makefile.am b/doc/Makefile.am index d30095df..6a04c5d6 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -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 diff --git a/doc/mkapiref.py b/doc/mkapiref.py index 3ab088d8..fc73e0b6 100755 --- a/doc/mkapiref.py +++ b/doc/mkapiref.py @@ -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)