-
-
Save callmehiphop/0081c0988c66546fa396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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