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.
This commit is contained in:
parent
41ac45785a
commit
c53502a261
|
@ -76,6 +76,7 @@ AC_PROG_LN_S
|
||||||
AC_PROG_MAKE_SET
|
AC_PROG_MAKE_SET
|
||||||
AM_PROG_CC_C_O
|
AM_PROG_CC_C_O
|
||||||
PKG_PROG_PKG_CONFIG([0.20])
|
PKG_PROG_PKG_CONFIG([0.20])
|
||||||
|
AM_PATH_PYTHON([2.6],, [:])
|
||||||
|
|
||||||
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
|
AX_CXX_COMPILE_STDCXX_11([noext], [optional])
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ help:
|
||||||
|
|
||||||
apiref.rst: $(top_builddir)/lib/includes/nghttp2/nghttp2ver.h \
|
apiref.rst: $(top_builddir)/lib/includes/nghttp2/nghttp2ver.h \
|
||||||
$(top_builddir)/lib/includes/nghttp2/nghttp2.h
|
$(top_builddir)/lib/includes/nghttp2/nghttp2.h
|
||||||
$(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
|
$(PYTHON) $(builddir)/mkapiref.py --header apiref-header.rst $^ > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm apiref.rst
|
-rm apiref.rst
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
# Generates API reference from C source code.
|
# Generates API reference from C source code.
|
||||||
|
from __future__ import print_function # At least python 2.6 is required
|
||||||
import re, sys, argparse
|
import re, sys, argparse
|
||||||
|
|
||||||
class FunctionDoc:
|
class FunctionDoc:
|
||||||
|
@ -32,10 +33,10 @@ class FunctionDoc:
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
|
|
||||||
def write(self, out):
|
def write(self, out):
|
||||||
print '''.. {}:: {}'''.format(self.domain, self.name)
|
print('''.. {}:: {}'''.format(self.domain, self.name))
|
||||||
print ''
|
print('')
|
||||||
for line in self.content:
|
for line in self.content:
|
||||||
print ' {}'.format(line)
|
print(' {}'.format(line))
|
||||||
|
|
||||||
class StructDoc:
|
class StructDoc:
|
||||||
def __init__(self, name, content, members, member_domain):
|
def __init__(self, name, content, members, member_domain):
|
||||||
|
@ -46,17 +47,17 @@ class StructDoc:
|
||||||
|
|
||||||
def write(self, out):
|
def write(self, out):
|
||||||
if self.name:
|
if self.name:
|
||||||
print '''.. type:: {}'''.format(self.name)
|
print('''.. type:: {}'''.format(self.name))
|
||||||
print ''
|
print('')
|
||||||
for line in self.content:
|
for line in self.content:
|
||||||
print ' {}'.format(line)
|
print(' {}'.format(line))
|
||||||
print ''
|
print('')
|
||||||
for name, content in self.members:
|
for name, content in self.members:
|
||||||
print ''' .. {}:: {}'''.format(self.member_domain, name)
|
print(''' .. {}:: {}'''.format(self.member_domain, name))
|
||||||
print ''
|
print('')
|
||||||
for line in content:
|
for line in content:
|
||||||
print ''' {}'''.format(line)
|
print(''' {}'''.format(line))
|
||||||
print ''
|
print('')
|
||||||
|
|
||||||
class MacroDoc:
|
class MacroDoc:
|
||||||
def __init__(self, name, content):
|
def __init__(self, name, content):
|
||||||
|
@ -64,10 +65,10 @@ class MacroDoc:
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
def write(self, out):
|
def write(self, out):
|
||||||
print '''.. macro:: {}'''.format(self.name)
|
print('''.. macro:: {}'''.format(self.name))
|
||||||
print ''
|
print('')
|
||||||
for line in self.content:
|
for line in self.content:
|
||||||
print ' {}'.format(line)
|
print(' {}'.format(line))
|
||||||
|
|
||||||
def make_api_ref(infiles):
|
def make_api_ref(infiles):
|
||||||
macros = []
|
macros = []
|
||||||
|
@ -99,12 +100,12 @@ def make_api_ref(infiles):
|
||||||
for title, docs in alldocs:
|
for title, docs in alldocs:
|
||||||
if not docs:
|
if not docs:
|
||||||
continue
|
continue
|
||||||
print title
|
print(title)
|
||||||
print '-'*len(title)
|
print('-'*len(title))
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
doc.write(sys.stdout)
|
doc.write(sys.stdout)
|
||||||
print ''
|
print('')
|
||||||
print ''
|
print('')
|
||||||
|
|
||||||
def process_macro(infile):
|
def process_macro(infile):
|
||||||
content = read_content(infile)
|
content = read_content(infile)
|
||||||
|
@ -204,6 +205,6 @@ if __name__ == '__main__':
|
||||||
help='source file')
|
help='source file')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.header:
|
if args.header:
|
||||||
print args.header.read()
|
print(args.header.read())
|
||||||
for infile in args.files:
|
for infile in args.files:
|
||||||
make_api_ref(args.files)
|
make_api_ref(args.files)
|
||||||
|
|
Loading…
Reference in New Issue