def _build_lineage_graph(cls): from abjad.tools import documentationtools addresses = ['abjad'] try: import experimental addresses.append('experimental') except ImportError: pass try: import ide addresses.append('ide') except ImportError: pass module_name, _, class_name = cls.__module__.rpartition('.') importlib.import_module(module_name) lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), )) graph = lineage.__graph__() maximum_node_count = 30 if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), ), lineage_prune_distance=2, ) graph = lineage.__graph__() if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), ), lineage_prune_distance=1, ) graph = lineage.__graph__() node_name = ClassDocumenter._get_node_name(module_name + '.' + class_name) if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=((module_name, class_name), ), ) graph = lineage.__graph__() graph_node = graph[node_name] graph_node.attributes['color'] = 'black' graph_node.attributes['fontcolor'] = 'white' graph_node.attributes['style'] = ('filled', 'rounded') graph_node = graph[node_name] graph_node.attributes['label'] = \ '<<B>{}</B>>'.format(graph_node.attributes['label']) return graph
def _get_lineage_graph(self, cls): def get_node_name(original_name): parts = original_name.split('.') name = [parts[0]] for part in parts[1:]: if part != name[-1]: name.append(part) if name[0] in ('abjad', 'experimental', 'ide'): return str('.'.join(name[2:])) return str('.'.join(name)) from abjad.tools import documentationtools module_name, _, class_name = cls.__module__.rpartition('.') node_name = '{}.{}'.format(cls.__module__, cls.__name__) importlib.import_module(module_name) lineage_graph_addresses = self._get_lineage_graph_addresses() lineage = documentationtools.InheritanceGraph( addresses=lineage_graph_addresses, lineage_addresses=((module_name, class_name),) ) graph = lineage.__graph__() maximum_node_count = 30 if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=lineage_graph_addresses, lineage_addresses=((module_name, class_name),), lineage_prune_distance=2, ) graph = lineage.__graph__() if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=lineage_graph_addresses, lineage_addresses=((module_name, class_name),), lineage_prune_distance=1, ) graph = lineage.__graph__() if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=((module_name, class_name),), ) graph = lineage.__graph__() graph_node = graph[node_name] graph_node.attributes['color'] = 'black' graph_node.attributes['fontcolor'] = 'white' graph_node.attributes['style'] = ('filled', 'rounded') graph_node = graph[node_name] graph_node.attributes['label'] = \ '<<B>{}</B>>'.format(graph_node.attributes['label']) return graph
def _get_tools_package_graph(self, tools_package): from abjad.tools import documentationtools inheritance_graph = documentationtools.InheritanceGraph( lineage_addresses=[tools_package.__package__]) lineage_graph = inheritance_graph.__graph__() lineage_graph.attributes['background'] = 'transparent' lineage_graph.attributes['rankdir'] = 'LR' return lineage_graph
def _get_tools_package_graph(self, tools_package): from abjad.tools import documentationtools lineage_graph_addresses = self._get_lineage_graph_addresses() inheritance_graph = documentationtools.InheritanceGraph( addresses=lineage_graph_addresses, lineage_addresses=[tools_package.__name__]) lineage_graph = inheritance_graph.__graph__() lineage_graph.attributes['bgcolor'] = 'transparent' lineage_graph.attributes['dpi'] = 72 lineage_graph.attributes['rankdir'] = 'LR' return lineage_graph
def run(self): from abjad.tools import documentationtools node = abjad_lineage() node.document = self.state.document env = self.state.document.settings.env parts = self.arguments[0].rpartition('.') module_name, class_name = str(parts[0]), str(parts[2]) # Create a graph starting with the list of classes try: if module_name.startswith('abjad'): addresses = ('abjad', ) elif module_name.startswith('experimental'): addresses = ('abjad', 'experimental') elif module_name.startswith('ide'): addresses = ('abjad', 'experimental', 'ide') else: addresses = (module_name.partition('.')[0], ) #raise InheritanceException( # 'Could not import class {!r} specified for ' # 'inheritance diagram'.format(self.arguments[0])) # The following is a hack. # We need to guarantee that everything is imported before # the first diagram in the entire document is drawn, # otherwise the InheritanceGraph doesn't see anything... why? module = importlib.import_module(module_name) #lineage = documentationtools.InheritanceGraph( # addresses=addresses, # lineage_addresses=((module_name, class_name),) # ) lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), )) graph = lineage.__graph__() except InheritanceException as err: return [ node.document.reporter.warning(err.args[0], line=self.lineno) ] maximum_node_count = 30 # begin pruning if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), ), lineage_prune_distance=2, ) graph = lineage.__graph__() # keep pruning if still too many nodes if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=addresses, lineage_addresses=((module_name, class_name), ), lineage_prune_distance=1, ) graph = lineage.__graph__() # finally, revert to subclass-less version if still too many nodes if maximum_node_count < len(graph.leaves): lineage = documentationtools.InheritanceGraph( addresses=((module_name, class_name), ), ) def get_node_name(original_name): parts = original_name.split('.') name = [parts[0]] for part in parts[1:]: if part != name[-1]: name.append(part) if name[0] in ('abjad', 'experimental'): return str('.'.join(name[2:])) return str('.'.join(name)) node_name = get_node_name(module_name + '.' + class_name) graph = lineage.__graph__() graph_node = graph[node_name] graph_node.attributes['color'] = 'black' graph_node.attributes['fontcolor'] = 'white' graph_node.attributes['style'] = ('filled', 'rounded') node['code'] = pickle.dumps(graph) node['kind'] = 'graphviz' node['is_pickled'] = True node['keep_original'] = True return [node]