def _find_variables_and_functions(module_list): "find all top-level variables, functions, and traits" obj_list = [ ] for m in module_list: temp = m.divide_children() children = [ (c.name.upper(), c.abs_name.upper(), c) for c in temp[0] + temp[2] + temp[3] ] obj_list.extend(children) # sort alphabetically by local name alpha_sort(obj_list) obj_list = [ r[2] for r in obj_list ] # group by first letter result = { } for obj in obj_list: letter = obj.name[0].upper() display_name = obj.name if isinstance(obj, docobjects.Function): display_name += '()' link = object_link(obj) text = obj.abs_name result[letter] = result.get(letter, [ ]) + [ (display_name, link, text) ] return result
def _find_variables_and_functions(module_list): "find all top-level variables, functions, and traits" obj_list = [] for m in module_list: temp = m.divide_children() children = [(c.name.upper(), c.abs_name.upper(), c) for c in temp[0] + temp[2] + temp[3]] obj_list.extend(children) # sort alphabetically by local name alpha_sort(obj_list) obj_list = [r[2] for r in obj_list] # group by first letter result = {} for obj in obj_list: letter = obj.name[0].upper() display_name = obj.name if isinstance(obj, docobjects.Function): display_name += '()' link = object_link(obj) text = obj.abs_name result[letter] = result.get(letter, []) + [(display_name, link, text)] return result
def _add_links(cls, hierarchy): """The hierarchicalize_modules function in the tools module does not know about HTML. This function generates links to objects organized in hierarchy.""" result = [ ] for obj, subobjs in hierarchy: subobjs = cls._add_links(subobjs) if obj.is_concrete(): link = object_link(obj) else: link = '' result.append((obj, link, subobjs)) return result
def _add_links(cls, hierarchy): """The hierarchicalize_modules function in the tools module does not know about HTML. This function generates links to objects organized in hierarchy.""" result = [] for obj, subobjs in hierarchy: subobjs = cls._add_links(subobjs) if obj.is_concrete(): link = object_link(obj) else: link = '' result.append((obj, link, subobjs)) return result
def write(self, obj): """Write HTML documentation * obj is a docobjects.DocObject instance to be documented (must be either Module or Class) This method produces a file PACKAGE.NAME.MODULE.NAME.html for modules, and PACKAGE.NAME.MODULE.NAME.CLASS.html for classes """ output_dir = self.options.docdir customheader = self.options.header customfooter = self.options.footer normative_obj_name = obj.abs_name package_namespace = self.package_namespace extrastyle = self.get_extra_style() disp_name = self._format_name_links(normative_obj_name, package_namespace) docstring = self._format_docstring(obj, obj.docstring) if isinstance(obj, docobjects.Module): # open output file fn = "%s.html" % normative_obj_name of = open(os.path.join(output_dir, fn), 'wt') # prepare arguments particular to modules title = "Module %s" % normative_obj_name header_title = "Module %s" % disp_name stylesheet = "module.css" template_name = 'module' obj.sort_sub_modules() sub_modules = [ (x.name, object_link(x), self._para_body( self._format_docstring(x, re.split('\.[ (\\n)]', x.docstring.strip())[0]))) for x in obj.sub_modules if not x.is_package() ] sub_packages = [ (x.name, object_link(x), x.docstring.strip().split('\n')[0]) for x in obj.sub_modules if x.is_package() ] imported_objects = [ (name, imp_obj.abs_name, object_link(imp_obj)) for name, imp_obj in obj.get_imported_objects() ] elif isinstance(obj, docobjects.Class): # open output file fn = "%s.html" % normative_obj_name of = open(os.path.join(output_dir, fn), 'wt') # prepare arguments particular to classes title = "Class %s" % normative_obj_name header_title = "Class %s" % disp_name stylesheet = "class.css" template_name = 'class' superclasses = [ (x.name, object_link(x), x.abs_name) for x in obj.get_bases() ] inh_attr_children, inh_class_children, inh_func_children, \ inh_traits_children = obj.inherited_children() inh_variables = [ (a.name, object_link(a)) for a in inh_attr_children ] inh_classes = [ (c.name, object_link(c)) for c in inh_class_children ] inh_functions = [ (f.name, format_params(f.argnames, f.defaults, f), object_link(f)) for f in inh_func_children ] inh_traits = [ (t.name, object_link(t)) for t in inh_traits_children ] # load html template template = self.template_loader.load(template_name) # this will hold our table of contents for use at the top of the page contents = [ ] # split children so that they can be linked to in appropriate sections attr_children, class_children, func_children, traits_children = \ obj.divide_children() # prepare template arguments variables = [ (a.name, self._format_docstring(a, a.docstring), '<pre>%s = %s\n\n</pre>' % (a.name, unparse(a.rhs_expr, a, False))) for a in attr_children ] classes = [ (c.name, object_link(c), self._para_body( self._format_docstring(c, re.split('\.[ (\\n)]', c.docstring.strip())[0]))) for c in class_children ] functions = [ (f.name, format_params(f.argnames, f.defaults, f), self._format_docstring(f, f.docstring)) for f in func_children ] traits = [ (t.name, self._format_docstring(t, t.docstring), '<pre>%s = %s\n\n</pre>' % (t.name, unparse(t.rhs_expr, t, True))) for t in traits_children ] # render template with local variables as arguments and write of.write(template.render(vars())) of.close() # recurse through class objects below this object for child in class_children: self.write(child)
def write(self, obj): """Write HTML documentation * obj is a docobjects.DocObject instance to be documented (must be either Module or Class) This method produces a file PACKAGE.NAME.MODULE.NAME.html for modules, and PACKAGE.NAME.MODULE.NAME.CLASS.html for classes """ output_dir = self.options.docdir customheader = self.options.header customfooter = self.options.footer normative_obj_name = obj.abs_name package_namespace = self.package_namespace extrastyle = self.get_extra_style() disp_name = self._format_name_links(normative_obj_name, package_namespace) docstring = self._format_docstring(obj, obj.docstring) if isinstance(obj, docobjects.Module): # open output file fn = "%s.html" % normative_obj_name of = open(os.path.join(output_dir, fn), 'wt') # prepare arguments particular to modules title = "Module %s" % normative_obj_name header_title = "Module %s" % disp_name stylesheet = "module.css" template_name = 'module' obj.sort_sub_modules() sub_modules = [(x.name, object_link(x), self._para_body( self._format_docstring( x, re.split('\.[ (\\n)]', x.docstring.strip())[0]))) for x in obj.sub_modules if not x.is_package()] sub_packages = [(x.name, object_link(x), x.docstring.strip().split('\n')[0]) for x in obj.sub_modules if x.is_package()] imported_objects = [ (name, imp_obj.abs_name, object_link(imp_obj)) for name, imp_obj in obj.get_imported_objects() ] elif isinstance(obj, docobjects.Class): # open output file fn = "%s.html" % normative_obj_name of = open(os.path.join(output_dir, fn), 'wt') # prepare arguments particular to classes title = "Class %s" % normative_obj_name header_title = "Class %s" % disp_name stylesheet = "class.css" template_name = 'class' superclasses = [(x.name, object_link(x), x.abs_name) for x in obj.get_bases()] inh_attr_children, inh_class_children, inh_func_children, \ inh_traits_children = obj.inherited_children() inh_variables = [(a.name, object_link(a)) for a in inh_attr_children] inh_classes = [(c.name, object_link(c)) for c in inh_class_children] inh_functions = [(f.name, format_params(f.argnames, f.defaults, f), object_link(f)) for f in inh_func_children] inh_traits = [(t.name, object_link(t)) for t in inh_traits_children] # load html template template = self.template_loader.load(template_name) # this will hold our table of contents for use at the top of the page contents = [] # split children so that they can be linked to in appropriate sections attr_children, class_children, func_children, traits_children = \ obj.divide_children() # prepare template arguments variables = [(a.name, self._format_docstring(a, a.docstring), '<pre>%s = %s\n\n</pre>' % (a.name, unparse(a.rhs_expr, a, False))) for a in attr_children] classes = [(c.name, object_link(c), self._para_body( self._format_docstring( c, re.split('\.[ (\\n)]', c.docstring.strip())[0]))) for c in class_children] functions = [(f.name, format_params(f.argnames, f.defaults, f), self._format_docstring(f, f.docstring)) for f in func_children] traits = [ (t.name, self._format_docstring(t, t.docstring), '<pre>%s = %s\n\n</pre>' % (t.name, unparse(t.rhs_expr, t, True))) for t in traits_children ] # render template with local variables as arguments and write of.write(template.render(vars())) of.close() # recurse through class objects below this object for child in class_children: self.write(child)