代码拉取完成,页面将自动刷新
import pydoc
import os, sys
module_header = "# Package {} Documentation\n"
class_header = "## Class {}"
function_header = "### {}"
def getmarkdown(module):
output = [ module_header.format(module.__name__) ]
if module.__doc__:
output.append(module.__doc__)
output.extend(getclasses(module))
return "\n".join((str(x) for x in output))
def getclasses(item):
output = list()
for cl in pydoc.inspect.getmembers(item, pydoc.inspect.isclass):
if cl[0] != "__class__" and not cl[0].startswith("_"):
# Consider anything that starts with _ private
# and don't document it
output.append( class_header.format(cl[0]))
# Get the docstring
output.append(pydoc.inspect.getdoc(cl[1]))
# Get the functions
output.extend(getfunctions(cl[1]))
# Recurse into any subclasses
output.extend(getclasses(cl[1]))
output.append('\n')
return output
def getfunctions(item):
output = list()
#print item
for func in pydoc.inspect.getmembers(item, pydoc.inspect.ismethod):
if func[0].startswith('_') and func[0] != '__init__':
continue
output.append(function_header.format(func[0].replace('_', '\\_')))
# Get the signature
output.append ('```py\n')
output.append('def %s%s\n' % (func[0], pydoc.inspect.formatargspec(*pydoc.inspect.getargspec(func[1]))))
output.append ('```\n')
# get the docstring
if pydoc.inspect.getdoc(func[1]):
output.append('\n')
output.append(pydoc.inspect.getdoc(func[1]))
output.append('\n')
return output
def generatedocs(module):
try:
sys.path.append(os.getcwd())
# Attempt import
mod = pydoc.safeimport(module)
if mod is None:
print("Module not found")
# Module imported correctly, let's create the docs
return getmarkdown(mod)
except pydoc.ErrorDuringImport as e:
print("Error while trying to import " + module)
if __name__ == '__main__':
print(generatedocs(sys.argv[1]))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。