]> rtime.felk.cvut.cz Git - opencv.git/blobdiff - opencv/doc/latex2sphinx/latex.py
cleanup names of doconly parameters
[opencv.git] / opencv / doc / latex2sphinx / latex.py
index a1296ab99afb14f4a556b6ee0e21a47e7bdcab04..4ef85c54203fbbfea9b769dbf61ec92cb5677764 100644 (file)
@@ -30,10 +30,13 @@ python_api = pythonapi.reader("../../interfaces/python/api")
 
 
 class SphinxWriter:
-    def __init__(self, filename, language):
+    def __init__(self, filename, language, abspath):
         assert language in ['py', 'c', 'cpp']
         self.language = language
 
+        self.abspath = abspath
+        os.path.abspath(os.path.dirname(filename))
+
         self.f_index = QOpen(os.path.join(self.language, filename), 'wt')
         self.f = self.f_index
         self.f_chapter = None
@@ -130,17 +133,19 @@ class SphinxWriter:
 
     def cmd_subsection(self, c):
         print >>self
-        print >>self, str(c.params[0])
-        print >>self, '-' * len(str(c.params[0]))
+        nm = str(c.params[0])
+        print >>self, nm
+        print >>self, '-' * len(nm)
         print >>self
         self.function_props = {}
+        self.covered.add(nm)
 
     def cmd_includegraphics(self, c):
         filename = os.path.join('..', '..', str(c.params[0]))
         print >>self, "\n\n.. image:: %s\n\n" % filename
 
     def cmd_cvCppCross(self, c):
-        self.write(":ref:`%s`" % str(c.params[0]))
+        self.write(":func:`%s`" % str(c.params[0]))
 
     def cmd_cvCPyCross(self, c):
         self.write(":ref:`%s`" % str(c.params[0]))
@@ -166,6 +171,7 @@ class SphinxWriter:
             print >>self, ".. ctype:: " + nm + "\n"
         print >>self
         self.addtag(nm, c)
+        self.state = 'class'
 
     def addtag(self, nm, c):
         if nm == "":
@@ -196,9 +202,11 @@ class SphinxWriter:
         self.indent = 0
         nm = self.render(c.params[0].str)
         print >>self, "\n.. index:: %s\n" % nm
-        print >>self, ".. _%s:\n" % nm
-        print >>self, nm
-        print >>self, '-' * len(nm)
+        if 0:
+            print >>self, "\n.. _%s:\n" % nm
+        print >>self
+        print >>self, 'cv::%s' % nm
+        print >>self, '-' * (4+len(nm))
         print >>self
         self.state = 'fpreamble'
         if self.description != "":
@@ -291,7 +299,7 @@ class SphinxWriter:
                     else:
                         doc_outs = l[2]
                     if len(outs) != len(doc_outs):
-                        self.report_error(c, "function %s output documented tuple %d, code %d" % (l[0], len(outs), len(doc_outs)))
+                        self.report_error(c, "function %s output code tuple %d, documented %d" % (l[0], len(outs), len(doc_outs)))
             else:
                 # self.report_error(c, "function %s documented but not found in code" % l[0])
                 pass
@@ -370,6 +378,11 @@ class SphinxWriter:
             self.f = self.saved_f
             self.indent = self.saved_indent
             print >>self
+            if self.language == 'py':
+                ckeys = ['#define', 'void', '#include', ';\n']
+                found = [repr(k) for k in ckeys if k in listing]
+                if len(found) > 0:
+                    self.report_error(c, 'listing is probably C, found %s' % ",".join(found))
             if (self.language == 'py') and ('>>>' in listing):
                 print >>self, "\n.. doctest::\n"
             else:
@@ -391,7 +404,7 @@ class SphinxWriter:
 
     def cmd_lstinputlisting(self, c):
         s = str(c.params[0])
-        print >>self.f, ".. include:: %s" % os.path.join('..', s)
+        print >>self.f, ".. include:: %s" % os.path.normpath(os.path.join(self.abspath, s))
         print >>self.f, "    :literal:"
         print >>self.f
 
@@ -426,6 +439,18 @@ class SphinxWriter:
             self.report_error(c, "Malformed cvarg")
             return
         e = self.ee()
+        if self.state == 'class':
+            nm = self.render(c.params[0].str)
+            if '->' in nm:
+                print >>self, "\n\n.. method:: %s\n\n" % nm
+            else:
+                print >>self, "\n\n.. attribute:: %s\n\n" % nm
+            self.indent += 1
+            print >>self
+            self.doL(c.params[1].str, False)
+            self.indent -= 1
+            print >>self
+            return
         is_func_arg = (e == ['description']) and (not 'done' in self.function_props)
         if is_func_arg:
             nm = self.render(c.params[0].str)
@@ -472,6 +497,12 @@ class SphinxWriter:
                 "cvarrseq" : ":class:`CvArr` or :class:`CvSeq`",
                 "CvPoint2D32fs" : "sequence of (float, float)",
                 "pts_npts_contours" : "list of lists of (x,y) pairs",
+                "CvSeqOfCvSURFPoint" : ":class:`CvSeq` of :class:`CvSURFPoint`",
+                "CvSeqOfCvSURFDescriptor" : ":class:`CvSeq` of list of float",
+                "cvpoint2d32f_count" : "int",
+                "ranges" : "list of tuples of ints",
+                "PyObject" : "object",
+                "edgeorpoint" : ":class:`CvSubdiv2DEdge`, :class:`CvSubdiv2DPoint`",
             }
             print >>self, "\n:type %s: %s" % (nm, translate.get(type, ':class:`%s`' % type))
 
@@ -645,6 +676,8 @@ def parseBib(filename, language):
 if 1:
     fulldoc = latexparser(sys.argv[1])
 
+    abspath = os.path.abspath(os.path.dirname(sys.argv[1]))
+
     raw = open('raw.full', 'w')
     for x in fulldoc:
         print >>raw, repr(x)
@@ -690,7 +723,7 @@ if 1:
         for x in doc:
             print >>raw, repr(x)
         raw.close()
-        sr = SphinxWriter('index.rst', language)
+        sr = SphinxWriter('index.rst', language, abspath)
         print >>sr, """
 OpenCV |version| %s Reference
 =================================