def module2md(self, module):
modname = module.__name__<EOL>path = self.get_src_path(module, append_base=False)<EOL>path = "<STR_LIT>".format(path, os.path.join(self.github_link, path))<EOL>found = set()<EOL>classes = []<EOL>line_nos = []<EOL>for name, obj in getmembers(module, inspect.isclass):<EOL><INDENT>found.add(name)<EOL>if not name.startswith("<STR_LIT:_>") and hasattr(obj, "<STR_LIT>") and obj.__module__ == modname:<EOL><INDENT>classes.append(self.class2md(obj))<EOL>line_nos.append(self.get_line_no(obj) or <NUM_LIT:0>)<EOL><DEDENT><DEDENT>classes = order_by_line_nos(classes, line_nos)<EOL>func2names = defaultdict(list)<EOL>for name, obj in getmembers(module, inspect.isfunction):<EOL><INDENT>func2names[obj].append(name)<EOL><DEDENT>functions = []<EOL>line_nos = []<EOL>for obj in func2names:<EOL><INDENT>names = func2names[obj]<EOL>found.update(names)<EOL>is_module_within_init = '<STR_LIT>' in path and obj.__module__.startswith(modname)<EOL>if is_module_within_init:<EOL><INDENT>found.add(obj.__module__.replace(modname + '<STR_LIT:.>', '<STR_LIT>'))<EOL><DEDENT>if hasattr(obj, "<STR_LIT>") and (obj.__module__ == modname or is_module_within_init):<EOL><INDENT>names = list(filter(lambda name: not name.startswith("<STR_LIT:_>"), names))<EOL>if len(names) > <NUM_LIT:0>:<EOL><INDENT>functions.append(self.func2md(obj, names=names))<EOL>line_nos.append(self.get_line_no(obj) or <NUM_LIT:0>)<EOL><DEDENT><DEDENT><DEDENT>functions = order_by_line_nos(functions, line_nos)<EOL>variables = []<EOL>line_nos = []<EOL>for name, obj in module.__dict__.items():<EOL><INDENT>if not name.startswith("<STR_LIT:_>") and name not in found:<EOL><INDENT>if hasattr(obj, "<STR_LIT>") and obj.__module__ != modname:<EOL><INDENT>continue<EOL><DEDENT>if hasattr(obj, "<STR_LIT>") and not obj.__name__.startswith(modname):<EOL><INDENT>continue<EOL><DEDENT>comments = inspect.getcomments(obj)<EOL>comments = "<STR_LIT>" % comments if comments else "<STR_LIT>"<EOL>variables.append("<STR_LIT>" % (name, comments))<EOL>line_nos.append(self.get_line_no(obj) or <NUM_LIT:0>)<EOL><DEDENT><DEDENT>variables = order_by_line_nos(variables, line_nos)<EOL>if variables:<EOL><INDENT>new_list = ["<STR_LIT>", "<STR_LIT>"]<EOL>new_list.extend(variables)<EOL>variables = new_list<EOL><DEDENT>string = MODULE_TEMPLATE.format(path=path,<EOL>global_vars="<STR_LIT:\n>".join(variables) if variables else "<STR_LIT>",<EOL>functions="<STR_LIT:\n>".join(functions) if functions else "<STR_LIT>",<EOL>classes="<STR_LIT>".join(classes) if classes else "<STR_LIT>")<EOL>return string<EOL>
Takes an imported module object and create a Markdown string containing functions and classes.