parser.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:tdoc 作者: Ryanb58 项目源码 文件源码
def parse_file(file_base, file_path, file_name):
    """Parse a python's files contents to extract API documentation."""
    src_path = os.path.join(file_base, file_path, file_name)
    print(src_path)

    with open(src_path) as fp:
        source = fp.read()
        tree = ast.parse(source)

        output_folder = "./docs/"
        dst_path = os.path.join(output_folder, file_path, file_name + ".md")

        os.makedirs(os.path.join(output_folder, file_path), exist_ok=True)

        with open(dst_path, "w") as output_file:

            class FuncLister(ast.NodeVisitor):
                def visit_FunctionDef(self, node):
                    """Function Visitor"""
                    output_file.write(get_function_markdown(node))
                    self.generic_visit(node)

                def visit_ClassDef(self, node):
                    """Class Visitor"""
                    output_file.write(get_class_markdown(node))
                    self.generic_visit(node)

            FuncLister().visit(tree)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号