按照PEP 257格式化docstring。
docformatter的Python项目详细描述
格式化文档字符串以跟随PEP 257。
功能
docformatter当前自动将docstring格式化为 PEP 257惯例的子集。以下是相关项目的报价 来自PEP 257。
- 为保持一致性,请始终在docstring周围使用三重双引号。
- 即使字符串适合一行,也使用三重引号。
- 多行docstrings由摘要行组成,就像一行一样 docstring,后面跟着一个空行,后面跟着一个更详细的 描述。
- 除非整个docstring适合一行,否则请放置右引号 自己一行。
docformatter还处理一些pep 8约定。
- 不要编写依赖于有效尾随的字符串文本 空白。这样的尾随空白在视觉上是无法区分的 一些编辑(或者最近的一些,reindent.py)将对它们进行裁剪。
安装
来自PIP:
$ pip install --upgrade docformatter
示例
运行后:
$ docformatter --in-place example.py
此代码
""" Here are some examples. This module docstring should be dedented."""deflaunch_rocket():"""Launch the rocket. Go colonize space."""deffactorial(x):''' Return x factorial. This uses math.factorial. '''importmathreturnmath.factorial(x)defprint_factorial(x):"""Print x factorial"""print(factorial(x))defmain():"""Main function"""print_factorial(5)iffactorial(10):launch_rocket()
格式化为此格式
"""Here are some examples. This module docstring should be dedented. """deflaunch_rocket():"""Launch the rocket. Go colonize space. """deffactorial(x):"""Return x factorial. This uses math.factorial. """importmathreturnmath.factorial(x)defprint_factorial(x):"""Print x factorial."""print(factorial(x))defmain():"""Main function."""print_factorial(5)iffactorial(10):launch_rocket()
选项
下面是帮助输出:
usage: docformatter [-h] [-i | -c] [-r] [--wrap-summaries length] [--wrap-descriptions length] [--blank] [--pre-summary-newline] [--make-summary-multi-line] [--force-wrap] [--range line line] [--version] files [files ...] Formats docstrings to follow PEP 257. positional arguments: files files to format or '-' for standard in optional arguments: -h, --help show this help message and exit -i, --in-place make changes to files instead of printing diffs -c, --check only check and report incorrectly formatted files -r, --recursive drill down directories recursively --wrap-summaries length wrap long summary lines at this length; set to 0 to disable wrapping (default: 79) --wrap-descriptions length wrap descriptions at this length; set to 0 to disable wrapping (default: 72) --blank add blank line after description --pre-summary-newline add a newline before the summary of a multi-line docstring --make-summary-multi-line add a newline before and after the summary of a one- line docstring --force-wrap force descriptions to be wrapped even if it may result in a mess --range line line apply docformatter to docstrings between these lines; line numbers are indexed at 1 --version show program's version number and exit
可能退出代码:
- 1-如果遇到任何错误
- 3-如果需要格式化任何文件(在--checkmode下)
包装说明
docformatter将包装描述,但仅限于简单的情况。如果有文本 这看起来像一个项目符号/编号列表,docformatter将离开 原样描述:
- Item one. - Item two. - Item three.
这样可以防止包装把东西弄得一团糟的风险。强迫 甚至这些要包装的实例也使用--force-wrap。
问题
可以在GitHub page上报告错误和修补程序。