def _generate_tokens(self, pkg_root_path, package_name, version,
                         namespace):
        """This method returns a dictionary of namespace and all public classes in each namespace
        """
        # Import ModuleNode.
        # Importing it globally can cause circular dependency since it needs NodeIndex that is defined in this file
        from apistub.nodes._module_node import ModuleNode

        self.module_dict = {}
        nodeindex = NodeIndex()
        # todo (Update the version number correctly)
        apiview = ApiView(nodeindex, package_name, 0, version, namespace)
        modules = self._find_modules(pkg_root_path)
        logging.debug("Modules to generate tokens: {}".format(modules))

        # find root module name
        root_module = ""
        if namespace:
            root_module = namespace.split(".")[0]

        # load all modules and parse them recursively
        for m in modules:
            if not m.startswith(root_module):
                logging.debug(
                    "Skipping module {0}. Module should start with {1}".format(
                        m, root_module))
                continue

            logging.debug("Importing module {}".format(m))
            try:
                module_obj = importlib.import_module(m)
                self.module_dict[m] = ModuleNode(m, module_obj, nodeindex)
            except:
                logging.error("Failed to import {}".format(m))

        # Create navigation info to navigate within APIreview tool
        navigation = Navigation(package_name, None)
        navigation.set_tag(NavigationTag(Kind.type_package))
        apiview.add_navigation(navigation)

        # Generate tokens
        modules = self.module_dict.keys()
        for m in modules:
            # Generate and add token to APIView
            logging.debug("Generating tokens for module {}".format(m))
            self.module_dict[m].generate_tokens(apiview)
            # Add navigation info for this modules. navigation info is used to build tree panel in API tool
            module_nav = self.module_dict[m].get_navigation()
            if module_nav:
                navigation.add_child(module_nav)
        return apiview
예제 #2
0
    def _generate_tokens(self, pkg_root_path, package_name, namespace, *,
                         source_url):
        """This method returns a dictionary of namespace and all public classes in each namespace
        """
        # Import ModuleNode.
        # Importing it globally can cause circular dependency since it needs NodeIndex that is defined in this file
        from apistub.nodes._module_node import ModuleNode

        self.module_dict = {}
        mapping = MetadataMap(pkg_root_path, mapping_path=self.mapping_path)
        apiview = ApiView(pkg_name=package_name,
                          namespace=namespace,
                          metadata_map=mapping,
                          source_url=source_url)
        modules = self._find_modules(pkg_root_path)
        logging.debug("Modules to generate tokens: {}".format(modules))

        # load all modules and parse them recursively
        for m in modules:
            if not m.startswith(namespace):
                logging.debug(
                    "Skipping module {0}. Module should start with {1}".format(
                        m, namespace))
                continue

            logging.debug("Importing module {}".format(m))
            module_obj = importlib.import_module(m)
            self.module_dict[m] = ModuleNode(m, module_obj, apiview.node_index,
                                             namespace)

        # Create navigation info to navigate within APIreview tool
        navigation = Navigation(package_name, None)
        navigation.tags = NavigationTag(Kind.type_package)
        apiview.add_navigation(navigation)

        # Generate tokens
        modules = self.module_dict.keys()
        for m in modules:
            self.module_dict[m].generate_diagnostics()
            # Generate and add token to APIView
            logging.debug("Generating tokens for module {}".format(m))
            self.module_dict[m].generate_tokens(apiview)
            # Add navigation info for this modules. navigation info is used to build tree panel in API tool
            module_nav = self.module_dict[m].get_navigation()
            if module_nav:
                navigation.add_child(module_nav)
        return apiview