def build_node_tree(self, source_paths):
import uqbar.apis<EOL>root = PackageNode()<EOL>for source_path in sorted(<EOL>source_paths, key=lambda x: uqbar.apis.source_path_to_package_path(x)<EOL>):<EOL><INDENT>package_path = uqbar.apis.source_path_to_package_path(source_path)<EOL>parts = package_path.split("<STR_LIT:.>")<EOL>if not self.document_private_modules and any(<EOL>part.startswith("<STR_LIT:_>") for part in parts<EOL>):<EOL><INDENT>continue<EOL><DEDENT>parent_node = root<EOL>if len(parts) > <NUM_LIT:1>:<EOL><INDENT>parent_package_path = "<STR_LIT:.>".join(parts[:-<NUM_LIT:1>])<EOL>try:<EOL><INDENT>parent_node = root[parent_package_path]<EOL><DEDENT>except KeyError:<EOL><INDENT>parent_node = root<EOL><DEDENT>try:<EOL><INDENT>if parent_node is root:<EOL><INDENT>grandparent_node = root<EOL>if len(parts) > <NUM_LIT:2>:<EOL><INDENT>grandparent_node = root[<EOL>parent_package_path.rpartition("<STR_LIT:.>")[<NUM_LIT:0>]<EOL>]<EOL><DEDENT>parent_node = PackageNode(name=parent_package_path)<EOL>grandparent_node.append(parent_node)<EOL>grandparent_node[:] = sorted(<EOL>grandparent_node, key=lambda x: x.package_path<EOL>)<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>parent_node = root<EOL><DEDENT><DEDENT>node_class = ModuleNode<EOL>if source_path.name == "<STR_LIT>":<EOL><INDENT>node_class = PackageNode<EOL><DEDENT>try:<EOL><INDENT>child_node = root[package_path]<EOL>child_node.source_path = source_path<EOL><DEDENT>except KeyError:<EOL><INDENT>child_node = node_class(name=package_path, source_path=source_path)<EOL>parent_node.append(child_node)<EOL>parent_node[:] = sorted(parent_node, key=lambda x: x.package_path)<EOL><DEDENT><DEDENT>for node in root.depth_first(top_down=False):<EOL><INDENT>kwargs = dict(<EOL>document_private_members=self.document_private_members,<EOL>member_documenter_classes=self.member_documenter_classes,<EOL>)<EOL>if isinstance(node, ModuleNode):<EOL><INDENT>node.documenter = self.module_documenter_class(<EOL>node.package_path, **kwargs<EOL>)<EOL><DEDENT>else:<EOL><INDENT>node.documenter = self.module_documenter_class(<EOL>node.package_path,<EOL>module_documenters=[<EOL>child.documenter<EOL>for child in node<EOL>if child.documenter is not None<EOL>],<EOL>**kwargs,<EOL>)<EOL><DEDENT>if (<EOL>not self.document_empty_modules<EOL>and not node.documenter.module_documenters<EOL>and not node.documenter.member_documenters<EOL>):<EOL><INDENT>node.parent.remove(node)<EOL><DEDENT><DEDENT>return root<EOL>
Build a node tree.