Skip to content

Instantly share code, notes, and snippets.

@callmehiphop
Forked from jgeewax/dox.py
Created February 11, 2016 18:35
Show Gist options
  • Save callmehiphop/0081c0988c66546fa396 to your computer and use it in GitHub Desktop.
Save callmehiphop/0081c0988c66546fa396 to your computer and use it in GitHub Desktop.
import argparse
import json
from parinx.parser import parse_docstring
import pdoc
def main():
parser = argparse.ArgumentParser(description='Document Python modules.')
parser.add_argument('module', nargs='*',
help='The name of the module (ie, requests.api)')
args = parser.parse_args()
info = []
for module_name in args.module:
info += get_module_info(module_name)
print json.dumps(info, indent=2)
def get_module_by_name(module_name):
return pdoc.Module(pdoc.import_module(module_name), allsubmodules=True)
def get_module_info(module_name):
module = get_module_by_name(module_name)
items = []
items += module.functions()
items += module.variables()
for cls in module.classes():
items += [cls]
items += cls.doc.values()
return map(get_item_info, items)
def get_item_info(item):
info = {}
if item.docstring and not isinstance(item, pdoc.Class):
cls = item.cls.cls if item.cls else None
info.update(parse_docstring(item.docstring, cls, strict=False))
info.update({
'name': item.refname,
'type': item.__class__.__name__.lower()})
return info
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment