3
3
4
4
"""
5
5
doc2md.py generates Python documentation in the Markdown (md) format. It was
6
- written to automatically generate documentation that can be put on Github
7
- or Bitbucket wiki pages. It is initially based on Ferry Boender's pydocmd.
6
+ written to automatically generate documentation that can be put on Github
7
+ or Bitbucket wiki pages. It is initially based on Ferry Boender's pydocmd.
8
8
9
9
It is as of yet not very complete and is more of a Proof-of-concept than a
10
10
fully-fledged tool. Markdown is also a very restricted format and every
16
16
$ python doc2md.py module [...]
17
17
18
18
doc2md.py scans every python file (.py) given and generates the documentation
19
- in a subfolder `doc`.
19
+ in a subfolder `doc`.
20
20
21
21
## Example output
22
22
23
+ - http://github.com/blasterbug/doc2md.py/wiki/doc2md
23
24
- http://github.com/blasterbug/SmileANN/wiki/neuron
24
25
- http://github.com/blasterbug/SmileANN/wiki/faces
25
- - http://github.com/blasterbug/doc2md.py/wiki/doc2md
26
-
26
+
27
27
"""
28
28
29
29
35
35
36
36
37
37
__author__ = "Benjamin Sientzoff"
38
- __version__ = "0.1b "
38
+ __version__ = "0.1.2b "
39
39
__maintainer__ = "Benjamin Sientzoff (blasterbug)"
40
40
__license__ = "GNU GPL V2"
41
41
@@ -109,7 +109,7 @@ def insp_mod(mod_name, mod_inst):
109
109
for func_name , func_inst in functions :
110
110
if func_inst .__module__ == mod_name :
111
111
info ['functions' ].append (insp_method (func_name , func_inst ))
112
-
112
+
113
113
# Get module classes
114
114
classes = inspect .getmembers (mod_inst , inspect .isclass )
115
115
if classes :
@@ -165,7 +165,7 @@ def insp_method(method_name, method_inst):
165
165
for pos , default in enumerate (method_args .defaults ):
166
166
info ['args' ][a_pos + pos ] = '%s=%s' % (info ['args' ][a_pos + pos ], default )
167
167
168
- # Print method documentation
168
+ # Print method documentation
169
169
method_doc = inspect .getdoc (method_inst )
170
170
if method_doc :
171
171
info ['doc' ] = fmt_doc (method_doc )
@@ -175,6 +175,8 @@ def insp_method(method_name, method_inst):
175
175
def to_markdown ( text_block ) :
176
176
"""
177
177
Markdownify an inspect file
178
+ :param text_block: inspect file to turn to Markdown
179
+ :return: Markdown doc into a string
178
180
"""
179
181
doc_output = ("# %s \n " % file_i ['name' ] )
180
182
doc_output += file_i ['doc' ] + ' \n '
@@ -184,7 +186,7 @@ def to_markdown( text_block ) :
184
186
if 'email' in file_i ['author' ]:
185
187
author += '<%s>' % (file_i ['author' ]['email' ])
186
188
if author :
187
- doc_output += str (" - __Author__: %s\n " % author )
189
+ doc_output += str ("\n __Author__: %s \n " % author )
188
190
189
191
author_attrs = [
190
192
('Version' , 'version' ),
@@ -193,7 +195,7 @@ def to_markdown( text_block ) :
193
195
]
194
196
for attr_friendly , attr_name in author_attrs :
195
197
if attr_name in file_i ['author' ]:
196
- doc_output += " - __%s__: %s \n " % (attr_friendly , file_i ['author' ][attr_name ])
198
+ doc_output += " __%s__: %s \n " % (attr_friendly , file_i ['author' ][attr_name ])
197
199
198
200
if file_i ['vars' ]:
199
201
doc_output += "\n ## Variables\n "
@@ -205,7 +207,7 @@ def to_markdown( text_block ) :
205
207
for function_i in file_i ['functions' ]:
206
208
if function_i ['name' ].startswith ('_' ):
207
209
continue
208
- doc_output += "\n \n ### def `%s(%s)`\n " % (function_i ['name' ], ', ' .join (function_i ['args' ]))
210
+ doc_output += "\n \n ### `%s(%s)`\n " % (function_i ['name' ], ', ' .join (function_i ['args' ]))
209
211
if function_i ['doc' ]:
210
212
doc_output += "%s" % (function_i ['doc' ])
211
213
else :
@@ -244,5 +246,3 @@ def to_markdown( text_block ) :
244
246
else :
245
247
sys .stderr .write ('Usage: %s <file.py>\n ' % (sys .argv [0 ]))
246
248
sys .exit (1 )
247
-
248
-
0 commit comments