예제 #1
0
def get_node_from_module(name):
    from mkapi.core.module import modules

    if isinstance(name, str):
        obj = get_object(name)
    else:
        obj = name

    return modules[obj.__module__].node[obj.__qualname__]
예제 #2
0
def get_module(name) -> Module:
    """Returns a Module instace by name or object.

    Args:
        name: Object name or object itself.
    """
    if isinstance(name, str):
        obj = get_object(name)
    else:
        obj = name

    return Module(obj)
예제 #3
0
def get_node(name, recursive: bool = True, sourcefile_index: int = 0) -> Node:
    """Returns a Node instace by name or object.

    Args:
        name: Object name or object itself.
        sourcefile_index: If `obj` is a member of class, this value is the index of
            unique source files given by `mro()` of the class. Otherwise, 0.
    """
    if isinstance(name, str):
        obj = get_object(name)
    else:
        obj = name

    return _get_node(obj, recursive, sourcefile_index)
예제 #4
0
파일: module.py 프로젝트: orf/mkapi
def get_module(name) -> Module:
    """Returns a Module instace by name or object.

    Args:
        name: Object name or object itself.
    """
    if isinstance(name, str):
        obj = get_object(name)
    else:
        obj = name

    name = obj.__name__
    if name in modules:
        return modules[name]
    else:
        module = Module(obj)
        modules[name] = module
        return module
예제 #5
0
    def on_config(self, config):
        """Inserts `src_dirs` to `sys.path`."""
        config_dir = os.path.dirname(config["config_file_path"])
        for src_dir in self.config["src_dirs"]:
            path = os.path.normpath(os.path.join(config_dir, src_dir))
            if path not in sys.path:
                sys.path.insert(0, path)
        if not self.config["src_dirs"]:
            path = os.getcwd()
            if path not in sys.path:
                sys.path.insert(0, path)
        self.pages = {}
        self.abs_api_paths = []
        if not self.server:
            config, self.abs_api_paths = mkapi.plugins.api.create_nav(
                config, self.config["filters"])
            global_config["config"] = config
            global_config["abs_api_paths"] = self.abs_api_paths
        else:
            config = global_config["config"]
            self.abs_api_paths = global_config["abs_api_paths"]

        if self.config["on_config"]:
            on_config = get_object(self.config["on_config"])
            kwargs = {}
            params = inspect.signature(on_config).parameters
            if "config" in params:
                kwargs["config"] = config
            if "mkapi" in params:
                kwargs["mkapi"] = self
            logger.info(
                f"[MkApi] Calling user 'on_config' with {list(kwargs)}")
            config_ = on_config(**kwargs)
            if config_ is not None:
                config = config_

        ext = config["markdown_extensions"]
        if "admonition" not in ext:
            config["markdown_extensions"].append("admonition")

        return config