From: Martin Ling Date: Sun, 25 Oct 2015 14:04:49 +0000 (+0000) Subject: python: Give all enum values __doc__ strings. X-Git-Tag: libsigrok-0.4.0~158 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=df979d6dc6949b1d5c3814b177cb71d6c40d03d4;p=libsigrok.git python: Give all enum values __doc__ strings. --- diff --git a/.gitignore b/.gitignore index 00abc7e4..95b1d5d6 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,8 @@ stamp-h? /bindings/python/sigrok/__pycache__/ /bindings/python/sigrok/core/classes.py /bindings/python/sigrok/core/classes_wrap.cpp -/bindings/python/sigrok/core/doc.i +/bindings/python/sigrok/core/doc_start.i +/bindings/python/sigrok/core/doc_end.i /bindings/python/sigrok/core/lowlevel.py /bindings/python/sigrok/core/lowlevel_wrap.c /bindings/python/timestamp diff --git a/Makefile.am b/Makefile.am index c47639f7..58115772 100644 --- a/Makefile.am +++ b/Makefile.am @@ -584,21 +584,27 @@ $(CPPXMLDOC): bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp \ if BINDINGS_PYTHON PDIR = bindings/python -PDOC = bindings/python/sigrok/core/doc.i +PDOC_START = bindings/python/sigrok/core/doc_start.i +PDOC_END = bindings/python/sigrok/core/doc_end.i setup_vars = VERSION='$(PACKAGE_VERSION)' CC='$(CXX)' CFLAGS='$(AM_CXXFLAGS) $(CXXFLAGS)' LDADD='$(PYSIGROK_LIBS)' setup_quiet = --quiet setup_py = $(PYTHON) $(srcdir)/$(PDIR)/setup.py $(setup_vars) $(setup_quiet) -$(PDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC) +$(PDOC_START): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC) $(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core - $(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py python $(CPPXMLDOC) > $@ + $(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py python $(CPPXMLDOC) start > $@ + +$(PDOC_END): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC) + $(AM_V_at)test -d $(PDIR)/sigrok/core || $(MKDIR_P) $(PDIR)/sigrok/core + $(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py python $(CPPXMLDOC) end > $@ python-build: $(PDIR)/timestamp $(PDIR)/timestamp: $(PDIR)/sigrok/core/classes.i \ - bindings/swig/classes.i bindings/swig/enums.i $(PDOC) \ - $(library_include_HEADERS) $(nodist_library_include_HEADERS) \ + bindings/swig/classes.i bindings/swig/enums.i $(PDOC_START) \ + $(PDOC_END) $(library_include_HEADERS) \ + $(nodist_library_include_HEADERS) \ $(bindings_cxx_libsigrokcxx_la_include_HEADERS) \ $(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS) \ @ORDER@ bindings/cxx/libsigrokcxx.la diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 9dd34ac6..46336549 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -384,7 +384,7 @@ std::map dict_to_map_options(PyObject *dict, %ignore sigrok::InputFormat::create_input; %ignore sigrok::OutputFormat::create_output; -%include "doc.i" +%include "doc_start.i" %define %attributevector(Class, Type, Name, Get) %rename(_ ## Get) sigrok::Class::Get; @@ -527,3 +527,5 @@ std::map dict_to_map_options(PyObject *dict, data = property(_data) } } + +%include "doc_end.i" diff --git a/bindings/swig/doc.py b/bindings/swig/doc.py index ffde9331..b9e20ade 100644 --- a/bindings/swig/doc.py +++ b/bindings/swig/doc.py @@ -21,7 +21,9 @@ from __future__ import print_function from xml.etree import ElementTree import sys, os -language, input_file = sys.argv[1:] +language, input_file = sys.argv[1:3] +if len(sys.argv) == 4: + mode = sys.argv[3] input_dir = os.path.dirname(input_file) index = ElementTree.parse(input_file) @@ -88,7 +90,14 @@ for compound in index.findall('compound'): trimmed_name, member_name)) print('%}') elif language == 'python' and constants: - print('%%extend %s {\n%%pythoncode %%{' % class_name) - for member_name, brief in constants: - print(' ## @brief %s\n %s = None' % (brief, member_name)) - print('%}\n}') + if mode == 'start': + print('%%extend %s {\n%%pythoncode %%{' % class_name) + for member_name, brief in constants: + print(' ## @brief %s\n %s = None' % (brief, member_name)) + print('%}\n}') + elif mode == 'end': + print('%pythoncode %{') + for member_name, brief in constants: + print('%s.%s.__doc__ = """%s"""' % ( + trimmed_name, member_name, brief)) + print('%}')