用于检查python源文件以确保正确的文档的实用程序。列出缺少的docstring,并计算docstring的总体覆盖率百分比评级
pydocstring-coverage的Python项目详细描述
Python文档字符串覆盖率
注:这完全是别人的工作。我做了一些改变(徽章的生成, 预提交钩子等),并希望它是pip可安装的。-@丹尼尔索。在
如果您的文档的健康状况非常糟糕,docstr-coverage
现在将看到您。在
docstr-coverage
是一个简单的工具,可以用来测量Python源代码的
docstring覆盖范围。它可以告诉你你的哪些功能,
类、方法和模块没有docstring。它还为个人提供关于docstring覆盖率的统计信息
文件,以及整个项目。在
示例
>>> HunterMcGushion$ docstr-coverage /docstr_coverage/
File: "docstr_coverage/setup.py"
- No module docstring
- No docstring for `readme`
Needed: 2; Found: 0; Missing: 2; Coverage: 0.0%
File: "docstr_coverage/docstr_coverage/__init__.py"
- No module docstring
Needed: 1; Found: 0; Missing: 1; Coverage: 0.0%
File: "docstr_coverage/docstr_coverage/coverage.py"
- No docstring for `DocStringCoverageVisitor.__init__`
Needed: 11; Found: 10; Missing: 1; Coverage: 90.9%
Overall statistics for 3 files:
Docstrings needed: 14; Docstrings found: 10; Docstrings missing: 4
Total docstring coverage: 71.4%; Grade: Very good
如何使用它?在
命令行工具
一般用法是:docstr-coverage <path to dir or module> [options]
要测试名为some_module.py
的单个模块,请运行:
要测试目录(递归),只需提供目录some_project/src
:
$ docstr-coverage some_project/src
选项:
- 在
--skipmagic,-m-忽略所有魔术方法(比如
在__init__
,和__str__
) - 在
--skipfiledoc,-f-忽略模块docstrings(在文件顶部)
在 - 在
--exclude=<;regex>;,-e<;regex>;要从分析中排除的文件路径模式
- 要排除虚拟环境
env
和您的tests
目录的内容,请运行:$ docstr-coverage some_project/ -e "env/*|tests/*"
- 要排除虚拟环境
- 在
--verbose=<;level>;,-v<;level>;—设置详细级别(0-3)
- 0-静音
- 1-打印总体统计数据
- 2-同时打印每个文件的单独统计信息
- 3-还打印缺少的docstring(函数名、类名等)
- 在
--docstr ignore file=<;filepath>;,-d<;filepath>;-包含要忽略的模式列表的filepath。模式是(文件模式,名称模式)对
- 文件内容示例:
在SomeFile method_to_ignore1 method_to_ignore2 method_to_ignore3 FileWhereWeWantToIgnoreAllSpecialMethods __.+__ .* method_to_ignore_in_all_files a_very_important_view_file ^get$ ^set$ ^post$ detect_.* get_val.*
项目中的包
也可以将docstr-coverage
作为项目的一部分,方法是将其导入:
fromdocstr_coverageimportget_docstring_coveragemy_coverage=get_docstring_coverage(['some_dir/file_0.py','some_dir/file_1.py'])
参数:
- 必需参数:
filenames
<;字符串文件名列表> - 可选参数:
skip_magic
<;bool>;,skip_file_docstring
<;bool>;,verbose
<;int(0-3)>;- 有关
get_docstring_coverage
及其参数的详细信息,请参见其documentation
- 有关
结果:
get_docstring_coverage
返回两个dict:1)每个文件的stats,和2)total stats。
有关详细信息,请参阅get_docstring_coverage
documentation
我为什么要用它?在
- 完整的文档对于帮助其他人(甚至您自己)理解您的代码非常重要
- 作为开发人员,在需要更新和修复错误时,提高代码的可维护性
- 作为一个用户,立即知道了解一个新的库是多么容易
- 如果它的文档覆盖率很低,那么您可能需要自己找出很多东西
安装
pip install docstr-coverage
如果您喜欢走在前沿,并且想要所有最新的发展,请运行:
pip install git+https://github.com/HunterMcGushion/docstr_coverage.git
特别感谢
感谢“数据贪婪”亚历克谢·斯特里科夫和詹姆斯·哈洛,感谢他们做了所有的努力工作。
docstr-coverage
只需恢复活力并将他们的努力引入python3。看到了吗谢谢.txt'了解更多信息。在
- 项目
标签: