Caffe2 - Python API
A deep learning, cross platform ML framework
github.py
1 
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 from caffe2.python.docs.formatter import Markdown
8 from caffe2.python.docs.generator import OpDocGenerator, DocUploader
9 from caffe2.python.docs.generator import OperatorDoc, OperatorEngine
10 import os
11 
12 
13 class GHOpDocUploader(DocUploader):
14  def __init__(self):
15  pass
16 
17  def upload(self, content_body):
18  print(content_body)
19 
20 
21 class GHMarkdown(Markdown):
22  def addHeader(self, text, h=1):
23  if h == 2:
24  h = 1
25  self.addLine("{header} {text}".format(header=h * '#', text=text), True)
26 
27  def addTable(self, table, noTitle=False):
28  self.addRaw("<table>")
29  for row in table:
30  self.addRaw("<tr>")
31  for cell in row:
32  self.addRaw("<td>")
33  self.addLine("{cell}".format(cell=cell))
34  self.addRaw("</td>")
35  self.addRaw("</tr>")
36  self.addRaw("</table>")
37 
38 
39 def getCodeLink(formatter, schema):
40  formatter = formatter.clone()
41  path = os.path.relpath(schema.file, "caffe2")
42  schemaLink = ('https://github.com/caffe2/caffe2/blob/master/{path}'
43  .format(path=path))
44  formatter.addLink('{path}'.format(path=path), schemaLink)
45  return formatter.dump()
46 
47 
48 class GHOperatorEngine(OperatorEngine):
49  def generateDoc(self, formatter, schema):
50  for device, _ in self.getDeviceImpl():
51  formatter.addCode('{engine}'.format(engine=self.engine), True)
52  if device:
53  formatter.addRaw(' on ')
54  formatter.addEmphasis("{device}".format(device=device), 1)
55 
56 
57 class GHOperatorDoc(OperatorDoc):
58  def generateCodeLink(self, formatter):
59  formatter.addHeader("Code", 3)
60  formatter.addRaw(getCodeLink(formatter, self.schema))
61 
62  def getInfo(self, formatter, name, impl):
63  formatter = formatter.clone()
64  if impl:
65  formatter.addEmphasis('{name}'.format(name=name), 1)
66  formatter.addRaw(' ')
67  formatter.addCode('{impl}'.format(impl=impl), True)
68  return formatter.dump()
69 
70 
71 class GHOpDocGenerator(OpDocGenerator):
72  def getOperatorDoc(self, name, schema, priority):
73  return GHOperatorDoc(name, schema, priority)
74 
75  def getOperatorEngine(self, name):
76  return GHOperatorEngine(name)
77 
78 
79 if __name__ == "__main__":
81  ops.createBody()
82  print(ops.content_body)