Преглед на файлове

added automatic generator of python doc strings

Former-commit-id: dada2856b71e48e065639a6a4e0c8912dc7f3884
Daniele Panozzo преди 10 години
родител
ревизия
5bb35585d9
променени са 3 файла, в които са добавени 76 реда и са изтрити 7 реда
  1. 2 0
      .gitignore
  2. 67 0
      python/mk_py_doc.py
  3. 7 7
      python/py_igl.cpp

+ 2 - 0
.gitignore

@@ -80,3 +80,5 @@ python/.idea
 untitled
 Untitled.ipynb
 python/.ipynb_checkpoints
+py_doc.cpp
+py_doc.h

+ 67 - 0
python/mk_py_doc.py

@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+#
+#  Syntax: mkdoc.py <path_of_header_files>
+#
+#  Extract documentation from C++ header files to use it in libiglPython bindings
+#
+
+import os, sys, glob
+
+#http://stackoverflow.com/questions/3207219/how-to-list-all-files-of-a-directory-in-python
+def get_filepaths(directory):
+    """
+    This function will generate the file names in a directory
+    tree by walking the tree either top-down or bottom-up. For each
+    directory in the tree rooted at directory top (including top itself),
+    it yields a 3-tuple (dirpath, dirnames, filenames).
+    """
+    file_paths = []  # List which will store all of the full filepaths.
+
+    # Walk the tree.
+    for root, directories, files in os.walk(directory):
+        for filename in files:
+            # Join the two strings in order to form the full filepath.
+            filepath = os.path.join(root, filename)
+            file_paths.append(filepath)  # Add it to the list.
+
+    return file_paths  # Self-explanatory.
+
+
+if __name__ == '__main__':
+
+    if len(sys.argv) != 2:
+        print('Syntax: %s <path_of_header_files>' % sys.argv[0])
+        exit(-1)
+
+    # Open two files, py_doc.h and py_doc.cpp
+    fh = open('py_doc.h', 'w')
+    fc = open('py_doc.cpp', 'w')
+
+    # List all files in the given folder and subfolders
+    base_path = sys.argv[1]
+    full_file_paths = get_filepaths(base_path)
+
+    # Add all the .h files
+    for f in full_file_paths:
+      if f.endswith(".h"):
+        f_clean = f[len(base_path):]
+        f_clean = f_clean.replace(base_path, "")
+        f_clean = f_clean.replace(".h", "")
+        f_clean = f_clean.replace("/", "_")
+        f_clean = f_clean.replace("\\", "_")
+        f_clean = f_clean.replace(" ", "_")
+        f_clean = f_clean.replace(".", "_")
+
+        tmp = open(f, 'r')
+        tmp_string = tmp.read()
+        tmp.close()
+
+        h_string = "extern const char *__doc_" + f_clean + ";\n"
+        cpp_string = "const char *__doc_" + f_clean + " = R\"igl_Qu8mg5v7(" + tmp_string + ")igl_Qu8mg5v7\";\n"
+
+        fh.write(h_string)
+        fc.write(cpp_string)
+
+    # Close files
+    fh.close()
+    fc.close()

+ 7 - 7
python/py_igl.cpp

@@ -17,7 +17,7 @@ void python_export_igl(py::module &m) {
   )
   {
     return igl::readOFF(str,V,F);
-  }, __doc_readOFF,
+  }, __doc_igl_readOFF,
   py::arg("str"), py::arg("V"), py::arg("F"));
 
   m.def("readOFF", []
@@ -29,7 +29,7 @@ void python_export_igl(py::module &m) {
   )
   {
     return igl::readOFF(str,V,F,N);
-  }, __doc_readOFF,
+  }, __doc_igl_readOFF,
   py::arg("str"), py::arg("V"), py::arg("F"), py::arg("N"));
 
 // writeOBJ.h
@@ -45,7 +45,7 @@ m.def("writeOBJ", []
 )
 {
   return igl::writeOBJ(str,V,F,CN,FN,TC,FTC);
-}, __doc_writeOBJ,
+}, __doc_igl_writeOBJ,
 py::arg("str"), py::arg("V"), py::arg("F"), py::arg("CN"), py::arg("FN"), py::arg("TC"), py::arg("FTC"));
 
 m.def("writeOBJ", []
@@ -56,7 +56,7 @@ m.def("writeOBJ", []
 )
 {
   return igl::writeOBJ(str,V,F);
-}, __doc_writeOBJ,
+}, __doc_igl_writeOBJ,
 py::arg("str"), py::arg("V"), py::arg("F"));
 
 // per_face_normals
@@ -70,7 +70,7 @@ m.def("per_face_normals", []
 )
 {
   return igl::per_face_normals(V,F,Z,N);
-}, __doc_per_face_normals,
+}, __doc_igl_per_face_normals,
 py::arg("V"), py::arg("F"), py::arg("Z"), py::arg("N"));
 
 m.def("per_face_normals", []
@@ -81,7 +81,7 @@ m.def("per_face_normals", []
 )
 {
   return igl::per_face_normals(V,F,N);
-}, __doc_per_face_normals,
+}, __doc_igl_per_face_normals,
 py::arg("V"), py::arg("F"), py::arg("N"));
 
 m.def("per_face_normals_stable", []
@@ -92,7 +92,7 @@ m.def("per_face_normals_stable", []
 )
 {
   return igl::per_face_normals_stable(V,F,N);
-}, __doc_per_face_normals,
+}, __doc_igl_per_face_normals,
 py::arg("V"), py::arg("F"), py::arg("N"));
 
 }