]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
moved generating kea-messages.rst and api.rst from Makefile.am to sphinx's conf.py...
authorMichal Nowikowski <godfryd@isc.org>
Fri, 9 Aug 2019 11:10:53 +0000 (13:10 +0200)
committerMichal Nowikowski <godfryd@isc.org>
Fri, 9 Aug 2019 11:10:53 +0000 (13:10 +0200)
doc/sphinx/Makefile.am
doc/sphinx/api2doc.py
doc/sphinx/conf.py
doc/sphinx/mes2doc.py

index ff83226d8d2fcba6d1373502056b702163610b3d..74449e23c47d914ba2a2718610a5133dca2e1735 100644 (file)
@@ -52,8 +52,6 @@ rst_arm_sources+=arm/netconf.rst
 rst_arm_sources+=arm/quickstart.rst
 rst_arm_sources+=arm/shell.rst
 rst_arm_sources+=arm/stats.rst
-rst_arm_sources+=$(srcdir)/api.rst
-rst_arm_sources+=$(srcdir)/kea-messages.rst
 
 main_sources=$(rst_arm_sources) conf.py $(static_sources)
 
@@ -102,6 +100,9 @@ mes_files+=$(top_srcdir)/src/bin/dhcp6/dhcp6_messages.mes
 mes_files+=$(top_srcdir)/src/bin/lfc/lfc_messages.mes
 mes_files+=$(top_srcdir)/src/bin/netconf/netconf_messages.mes
 
+# this env variable is used in sphinx's conf.py where mes2doc.py is invoked
+export KEA_MES_FILES=$(mes_files)
+
 # list of api files that are used to generate api.rst
 api_files=
 api_files+=$(srcdir)/api/build-report.json
@@ -227,6 +228,9 @@ api_files+=$(srcdir)/api/subnet6-list.json
 api_files+=$(srcdir)/api/subnet6-update.json
 api_files+=$(srcdir)/api/version-get.json
 
+# this env variable is used in sphinx's conf.py where api2doc.py is invoked
+export KEA_API_FILES=$(api_files)
+
 EXTRA_DIST += $(api_files)
 
 if HAVE_PDFLATEX
@@ -235,13 +239,6 @@ else
 all: html mans
 endif
 
-$(srcdir)/kea-messages.rst: $(mes_files) mes2doc.py
-       $(PYTHON) $(srcdir)/mes2doc.py -o $@ $(mes_files)
-
-
-$(srcdir)/api.rst: $(api_files) api2doc.py
-       $(PYTHON) $(srcdir)/api2doc.py -o $@ $(api_files)
-
 
 PDFLATEX_AND_OPTS=$(PDFLATEX) -interaction nonstopmode
 
@@ -289,7 +286,7 @@ uninstall-local:
 
 clean-local:
        rm -rf $(sphinxbuilddir)
-       rm -f $(srcdir)/kea-messages.rst  # $(srcdir)/api.rst
+       rm -f $(srcdir)/kea-messages.rst $(srcdir)/api.rst
 
 .PHONY: all pdf html mans
 
index 2dc60cc91666b7ad524e89718470d5d3dd091f05..8f49edffd5f52d774ea0bb7593c05945379d71a1 100755 (executable)
@@ -30,7 +30,7 @@ def read_input_files(files):
     for f in files:
         name = os.path.basename(f)[:-5]
         # Skip special names starting with _ (such as _template.json)
-        if name[0] == '_':
+        if name.startswith('_'):
             print("Skipping %s (starts with underscore)" % f)
             continue
         with open(f) as fp:
@@ -170,18 +170,23 @@ API Reference
     return rst
 
 
-def main():
-    args = parse_args()
-
-    apis = read_input_files(args.files)
+def generate(in_files, out_file):
+    apis = read_input_files(in_files)
 
     rst = generate_rst(apis)
 
-    if args.output:
-        with open(args.output, 'w') as f:
+    if out_file:
+        with open(out_file, 'w') as f:
             f.write(rst)
+        print('Wrote generated RST content to: %s' % out_file)
     else:
         print(rst)
 
+
+def main():
+    args = parse_args()
+    generate(args.files, args.output)
+
+
 if __name__ == '__main__':
     main()
index beb5ef897c7d9e5ac0824454fb36ea6b1e41b46d..482f047c7245f41fda2ed248e06f493bd4f11966 100644 (file)
@@ -182,6 +182,25 @@ man_pages = [
 todo_include_todos = True
 
 
+
+# Do generation of api.rst and kea-messages.rst here in conf.py instead of Makefile.am
+# so they are available on ReadTheDocs as there makefiles are not used for building docs.
+def run_generate_docs(_):
+    import os
+    import sys
+    src_dir = os.path.abspath(os.path.dirname(__file__))
+    print(src_dir)
+    sys.path.append(src_dir)
+
+    import api2doc
+    api2doc.generate(os.getenv('KEA_API_FILES').split(), os.path.join(src_dir, 'api.rst'))
+
+    import mes2doc
+    mes2doc.generate(os.getenv('KEA_MES_FILES').split(), os.path.join(src_dir, 'kea-messages.rst'))
+
+
 # custom setup hook
 def setup(app):
     app.add_stylesheet('kea.css')
+
+    app.connect('builder-inited', run_generate_docs)
index 12f8b697e4865bff2284c35cf90a72ab0fc54eb6..eb7f412bffc85dc3f8b96e6d596af7d3cd5a2904 100755 (executable)
@@ -37,6 +37,7 @@ def read_input_files(files):
     messages = {}
     for f in files:
         with open(f) as fp:
+            print("Processing %s" % f)
             namespace = None
             msg_descr = None
             msg_id = None
@@ -108,18 +109,23 @@ Kea, can be found in ISC's `Knowledgebase <https://kb.isc.org/docs/kea-administr
 
     return rst
 
-def main():
-    args = parse_args()
-
-    messages = read_input_files(args.files)
+def generate(in_files, out_file):
+    messages = read_input_files(in_files)
 
     rst = generate_rst(messages)
 
-    if args.output:
-        with open(args.output, 'w') as f:
+    if out_file:
+        with open(out_file, 'w') as f:
             f.write(rst)
+        print('Wrote generated RST content to: %s' % out_file)
     else:
         print(rst)
 
+
+def main():
+    args = parse_args()
+    generate(args.files, args.output)
+
+
 if __name__ == '__main__':
     main()