PEP8只清除自上次提交、上一次提交或分支(合并基)以来接触过的部分文件。
pep8radius的Python项目详细描述
PEP8半径
PEP8只清理 自上次提交、上次提交或 (分支的合并基)分支。
修复PEP8违规项目(“PEP8风暴”) 若要合并冲突,请在合并/拉取请求和中断(git)中添加噪波 责怪。PEP8RADIUS通过只固定PEP8解决了这个问题。 在你所做的项目中没有发现违规行为 工作,留下这些部分“比你发现的更好” 把你的承诺集中在你曾经的代码库中 实际上是在工作。
安装
来自PIP:
$ pip install pep8radius
用法
使用pep8radius的gif
- 移到项目目录
- 对项目进行一些更改
- 运行pep8radius --diff # view a diff of proposed fixed
- 运行pep8radius --in-place # apply the fixes
- 提交更改
对于分支,可以使用与git diff相同的语法:
$ pep8radius master # branch name to compare against (compares against merge-base) $ pep8radius c12166f # commit hash $ pep8radius master --in-place # these work with other options too
您还可以修复docstring (PEP257)使用 docformatter选项:
$ pep8radius --docformatter --diff
注意:还可以为“pep8radius”使用“btyfi”别名。
通过管道将差异传递到 cdiff(这使得diff非常漂亮 有很多选择:
$ pep8radius --diff --no-color | cdiff $ pep8radius --diff --no-color | cdiff --side-by-side
[alias]rad= !pep8radius master --diff --no-color $@| cdiff --side-by-side
输出修正如下:
吉特拉德
$ git diff master | pep8radius --diff --from-diff=-
yapf
使用yapf作为替代 后端,您可以传递--yapf选项:
$ pep8radius master --diff --yapf $ pep8radius master --diff --yapf --style=google
注意:这将忽略autopep8和docformatter特定的参数。
配置文件
pep8radius查找pep8 docs中描述的配置文件。
在项目级别,您可能有一个setup.cfg,其中包含一个pep8 第节,您可以使用它定义pep8radius和 自动第8步:
[pep8] rev = master ignore = E226,E302,E41 max-line-length = 160
默认情况下,这将查找用户级别的默认值,您可以抑制 这是通过向global_config:
[pep8] rev = staging global_config =
或者您可能想将yapf与google风格结合使用:
[pep8] rev = master yapf = True style = google
注意:样式也可以是配置文件或dict(请参阅yapf文档)。
VCS支持
Git,Mecurial (hg)(暂定) Bazaar。请请求支持 上的其他版本控制系统 github。
选项
$ pep8radius --help usage: pep8radius [-h][--version][-d][-i][--no-color][-v][--from-diff DIFF][-p n][-a][--experimental][--exclude globs][--list-fixes][--ignore errors][--select errors][--max-line-length n][--indent-size n][-f][--no-blank][--pre-summary-newline][--force-wrap][--global-config GLOBAL_CONFIG][--ignore-local-config][rev] PEP8 clean only the parts of the files which you have touched since the last commit, a previous commit or (the merge-base of) a branch. positional arguments: rev commit or name of branch to compare against optional arguments: -h, --help show this help message and exit --version print version number and exit -d, --diff print the diff of fixed source vs original -i, --in-place make the fixes in place; modify the files --no-color do not print diffs in color (default is to use color) -v, --verbose print verbose messages; multiple -v result in more verbose messages (one less -v is passed to autopep8) --from-diff DIFF Experimental: rather than calling out to version control, just pass in a diff; the modified lines will be fixed pep8: Pep8 options to pass to autopep8. -p n, --pep8-passes n maximum number of additional pep8 passes (default: infinite) -a, --aggressive enable non-whitespace changes; multiple -a result in more aggressive changes --experimental enable experimental fixes --exclude globs exclude file/directory names that match these comma- separated globs --list-fixes list codes for fixes and exit; used by --ignore and --select --ignore errors do not fix these errors/warnings (default: E24) --select errors fix only these errors/warnings (e.g. E4,W) --max-line-length n set maximum allowed line length (default: 79) --indent-size n number of spaces per indent level (default 4) docformatter: Fix docstrings for PEP257. -f, --docformatter Use docformatter --no-blank Do not add blank line after description --pre-summary-newline add a newline before the summary of a multi-line docstring --force-wrap force descriptions to be wrapped even if it may result in a mess config: Change default options based on global or local(project) config files. --global-config filename path to global pep8 config file;if this file does not exist then this is ignored (default: ~/.config/pep8) --ignore-local-config don't look for and apply local config files; if not passed, defaults are updated with any config files in the project's root dir yapf: Options for yapf, alternative to autopep8. Currently any other options are ignored. -y, --yapf Use yapf rather than autopep8. This ignores other arguments outside of this group. --style style either pep8, google, name of file with stylesettings, or a dict Run before you commit, against a previous commit or branch before merging.
有关这些选项的详细信息,请参见 ` autopep8<;https://pypi.python.org/pypi/autopep8>;``。
作为模块
pep8radius还围绕autopep8导出轻量级包装,以便 可以用fix_code或fix_file修复代码的行范围。
下面是来自autopep8’s README:
的“错误代码”示例importmath,sys;defexample1():####This is a long comment. This should be wrapped to fit within 72 characters.some_tuple=(1,2,3,'a');some_variable={'long':'Long code lines should be wrapped within 79 characters.','other':[math.pi,100,200,300,9876543210,'This is a long string that goes on'],'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,20,300,40000,500000000,60000000000000000]}}return(some_tuple,some_variable)defexample2():return{'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));classExample3(object):def__init__(self,bar):#Comments should have a space after the hash.ifbar:bar+=1;bar=bar*bar;returnbarelse:some_string=""" Indentation in multiline strings should not be touched. Only actual code should be reindented. """return(sys.path,some_string)
您可以修正行范围1-1(导入)和12-21(导入 Example3class)与 pep8radius.fix_code(code, [(1, 1), (12, 21)])(其中代码是 上面的字符串),返回在这些范围内固定的代码:
importmathimportsysdefexample1():####This is a long comment. This should be wrapped to fit within 72 characters.some_tuple=(1,2,3,'a');some_variable={'long':'Long code lines should be wrapped within 79 characters.','other':[math.pi,100,200,300,9876543210,'This is a long string that goes on'],'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,20,300,40000,500000000,60000000000000000]}}return(some_tuple,some_variable)defexample2():return{'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));classExample3(object):def__init__(self,bar):# Comments should have a space after the hash.ifbar:bar+=1bar=bar*barreturnbarelse:some_string=""" Indentation in multiline strings should not be touched. Only actual code should be reindented. """return(sys.path,some_string)
您可以使用fix_file直接在文件上执行此操作,这将为您提供 在适当的地方这样做的选择。
pep8radius.fix_code('code.py',[(1,1),(12,21)],in_place=True)
也可以使用 parse_args。例如忽略长线(E501)并使用 全局配置文件中的选项:
args=pep8radius.parse_args(['--ignore=E501','--ignore-local-config'],apply_config=True)pep8radius.fix_code(code,[(1,1),(12,21)],options=args)