分析来自不同源文件的注释。

comment-parser的Python项目详细描述


注释分析器

Build StatusPyPI statusPyPI version shields.ioPyPI licensePyPI pyversions

python模块用于从各种类型的源代码文件中提取注释。

安装

先决条件

  • libmagic

Linux/Unix

sudo pip3 install comment_parser

OSX和Windows

另外,完成 python-magic

用法

要使用,只需运行:

>>>fromcomment_parserimportcomment_parser>>># Returns a list of comment_parser.parsers.common.Comments>>>comment_parser.extract_comments('/path/to/source_file')>>># Or>>>comment_parser.extract_comments_from_str('...')

提取评论签名

defextract_comments(filename,mime=None):"""Extracts and returns the comments from the given source file.    Args:        filename: String name of the file to extract comments from.        mime: Optional MIME type for file (str). Note some MIME types accepted            don't comply with RFC2045. If not given, an attempt to deduce the            MIME type will occur.    Returns:        Python list of parsers.common.Comment in the order that they appear in            the source file.    Raises:        UnsupportedError: If filename is of an unsupported MIME type.    """passdefextract_comments_from_str(code,mime=None):"""Extracts and returns comments from the given source string.    Args:        code: String containing code to extract comments from.        mime: Optional MIME type for code (str). Note some MIME types accepted            don't comply with RFC2045. If not given, an attempt to deduce the            MIME type will occur.    Returns:        Python list of parsers.common.Comment in the order that they appear in            the source code.    Raises:        UnsupportedError: If code is of an unsupported MIME type.    """pass

评论界面

classComment(object):"""Represents comments found in source files."""deftext(self):"""Returns the comment's text.        Returns:            String        """passdefline_number(self):"""Returns the line number the comment was found on.        Returns:            Int        """passdefis_multiline(self):"""Returns whether this comment was a multiline comment.        Returns:            True if comment was a multiline comment, False if not.        """passdef__str__(self):passdef__eq__(self,other):pass

开发

本地运行

在仓库的底部启动python3。

fromcomment_parserimportcomment_parsercomment_parser.extract_comments('foo.c',mime='text/x-c')

运行测试

python3 setup.py test

运行Pylint

pylint comment_parser

正在运行格式化程序

yapf -rip --style=chromium .

部署到pypi

python3 setup.py sdist
twine upload dist/*

支持的编程语言

LanguageMime String
Ctext/x-c
C++/C#text/x-c++
Gotext/x-go
HTMLtext/html
Javatext/x-java-source
Javascriptapplication/javascript
Rubytext/x-ruby
Shelltext/x-shellscript
XMLtext/xml

还有更多!

检查comment\u parser.py中对应的mime类型。

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

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener