Python代码的自动样式指南和docstrings生成器

alphadoc的Python项目详细描述


阿尔法多克

PyPI versionISSUESPULL REQUESTS

自动docstring生成器和样式指南,支持Python中文档的许多指定约定。在

特点

  • 使用可自定义的函数模板自动生成docstring。在
  • 根据python的标准PEP-8样式约定自动修复代码。在
  • 支持常见和广泛使用的docstring格式,如Numpy、Google、structured Text和Epytext(Javadoc)

安装

使用pip:

$ pip install alphadoc

使用

alphadoc将文件名和格式类型作为参数

^{pr2}$

有关更多命令行开关和选项,请参见alphadoc --help!在

选项:

Usage: alphadoc [OPTIONS] FILENAME

  Automatic docstring generator and style guide that  supports a
  number of specified conventions for formatting  as well as
  documentation in Python.

Options:
  -d, --doc_format TEXT  Specified format for docstrings from Options-
                         ReST : For ReStructured Text (default); Epytext
                         :  For Epytext (Javadoc); Google : For Google-
                         Style ; Numpydoc : For Numpydoc

  --help                 Show this message and exit.

示例:

在alphadoc之前

importastimportsysdeftop_level_functions(body):return(fforfinbodyifisinstance(f,ast.FunctionDef))defparse_ast(filename):withopen(filename,"rt")asfile:returnast.parse(file.read(),filename=filename)defget_func(filename):tree=parse_ast(filename)func_list=[]forfuncintop_level_functions(tree.body):func_list.append(func.name)returnfunc_list

在alphadoc之后

Docstring格式:

  • structured Text(默认)
importastimportsysdeftop_level_functions(body):"""        This is reST style.        :param param1: this is a first param        :param param2: this is a second param        :returns: this is a description of what is returned        :raises keyError: raises an exception    """return(fforfinbodyifisinstance(f,ast.FunctionDef))defparse_ast(filename):"""        This is reST style.        :param param1: this is a first param        :param param2: this is a second param        :returns: this is a description of what is returned        :raises keyError: raises an exception    """withopen(filename,"rt")asfile:returnast.parse(file.read(),filename=filename)defget_func(filename):"""        This is reST style.        :param param1: this is a first param        :param param2: this is a second param        :returns: this is a description of what is returned        :raises keyError: raises an exception    """tree=parse_ast(filename)func_list=[]forfuncintop_level_functions(tree.body):func_list.append(func.name)returnfunc_list
  • Epytext(Javadoc)
importastimportsysdeftop_level_functions(body):"""        This is javadoc style.        @param param1: this is a first param        @param param2: this is a second param        @return: this is a description of what is returned        @raise keyError: raises an exception    """return(fforfinbodyifisinstance(f,ast.FunctionDef))defparse_ast(filename):"""        This is javadoc style.        @param param1: this is a first param        @param param2: this is a second param        @return: this is a description of what is returned        @raise keyError: raises an exception    """withopen(filename,"rt")asfile:returnast.parse(file.read(),filename=filename)defget_func(filename):"""        This is javadoc style.        @param param1: this is a first param        @param param2: this is a second param        @return: this is a description of what is returned        @raise keyError: raises an exception    """tree=parse_ast(filename)func_list=[]forfuncintop_level_functions(tree.body):func_list.append(func.name)returnfunc_list
  • Google
importastimportsysdeftop_level_functions(body):"""            This is an example of Google style.            Args:            param1: This is the first param.            param2: This is a second param.            Returns:            This is a description of what is returned.            Raises:            KeyError: Raises an exception.    """return(fforfinbodyifisinstance(f,ast.FunctionDef))defparse_ast(filename):"""            This is an example of Google style.            Args:            param1: This is the first param.            param2: This is a second param.            Returns:            This is a description of what is returned.            Raises:            KeyError: Raises an exception.    """withopen(filename,"rt")asfile:returnast.parse(file.read(),filename=filename)defget_func(filename):"""            This is an example of Google style.            Args:            param1: This is the first param.            param2: This is a second param.            Returns:            This is a description of what is returned.            Raises:            KeyError: Raises an exception.    """tree=parse_ast(filename)func_list=[]forfuncintop_level_functions(tree.body):func_list.append(func.name)returnfunc_list
  • Numpydoc
importastimportsysdeftop_level_functions(body):"""        Numpydoc description of a kind        of very exhautive numpydoc format docstring.        Parameters        ----------        first : array_like            the 1st param name `first`        second :            the 2nd param        third : {'value', 'other'}, optional            the 3rd param, by default 'value'        Returns        -------        string            a value in a string        Raises        ------        KeyError            when a key error        OtherError            when an other error    """return(fforfinbodyifisinstance(f,ast.FunctionDef))defparse_ast(filename):"""        Numpydoc description of a kind        of very exhautive numpydoc format docstring.        Parameters        ----------        first : array_like            the 1st param name `first`        second :            the 2nd param        third : {'value', 'other'}, optional            the 3rd param, by default 'value'        Returns        -------        string            a value in a string        Raises        ------        KeyError            when a key error        OtherError            when an other error    """withopen(filename,"rt")asfile:returnast.parse(file.read(),filename=filename)defget_func(filename):"""        Numpydoc description of a kind        of very exhautive numpydoc format docstring.        Parameters        ----------        first : array_like            the 1st param name `first`        second :            the 2nd param        third : {'value', 'other'}, optional            the 3rd param, by default 'value'        Returns        -------        string            a value in a string        Raises        ------        KeyError            when a key error        OtherError            when an other error    """tree=parse_ast(filename)func_list=[]forfuncintop_level_functions(tree.body):func_list.append(func.name)returnfunc_list

参考文献

http://daouzli.com/blog/docstring.html

贡献

alphadoc是完全开放的源代码和开放的贡献!我们要求您遵守我们在CODE_OF_CONDUCT.mdCONTRIBUTING.md中定义的贡献指导原则

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
泛型Java将参数约束到公共超类   java Spring引导:在构造函数中加载属性文件并用作autowire注释   java中的优先级队列顺序错误。util。优先级队列和特定比较器   带有Java Sprint引导REST的Google应用程序引擎标准在GCLOUD服务器中不起作用   安卓从Java代码中检索变量并将其作为参数分配给TestNG   用于读取列表值的Java JSON对象   java Hibernate映射:实体映射中的重复列   多线程。start()不从Java中的父线程分派   java Android facebook webdialog网络错误(netstack:lib_mgr错误)   http使用Java阻止网站   java DynamicAsper:访问连接报表中动态列的值   java如何分离文件中的每个单词,并在表中显示每个单词和每个单词的编号?   如何打包和部署EclipseJava应用程序?   java使用Mule Anypoint,我想实现没有flowref的功能   java Kafka consumer ClassNotFoundException   java错误捕获帮助;消息不断重复   javaspring,Thymeleaf和CSS如何给错误着色   javascript如何在java中实现反向ajax   如何通过UDP连接从java数据包中读取序列号?