调用Flake8¶
Once you have installed Flake8, you can begin using it. Most of the time, you will be able to generically invoke Flake8 like so:
flake8 ...
只需允许在终端中运行的shell定位 Flake8 . 但在某些情况下,您可能已经安装了 Flake8 对于Python的多个版本(例如python2.7和python3.5),您需要调用特定的版本。在这种情况下,使用以下方法可以获得更好的结果:
python2.7 -m flake8
或
python3.5 -m flake8
因为这会告诉运行正确版本的Python Flake8 .
注解
安装 Flake8 once不会同时在Python2.7和Python3.5上安装它。它只为运行pip的Python版本安装它。
也可以将命令行选项直接指定给 Flake8 :
flake8 --select E123
或
python<version> -m flake8 --select E123
注解
这是我们最后一次展示两个版本的调用。从现在开始,我们只需使用 flake8
假设用户知道他们可以使用 python<version> -m flake8
相反。
也可以缩小 Flake8 将尝试通过精确指定要检查的路径和目录来进行检查。假设我们有一个目录,其中包含python文件,子目录中有python文件(可能还有更多的子目录) my_project
. 如果我们只想从文件中找到错误 my_project
我们可以:
flake8 my_project
如果我们只想要某些错误(例如。, E123
)从该目录中的文件中,我们还可以执行以下操作:
flake8 --select E123 my_project
你可以在命令行中使用更多的选项 --help
选项:
flake8 --help
你应该会看到这样的东西:
Usage: flake8 [options] file file ...
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose Print more information about what is happening in
flake8. This option is repeatable and will increase
verbosity each time it is repeated.
-q, --quiet Report only file names, or nothing. This option is
repeatable.
--count Print total number of errors and warnings to standard
error and set the exit code to 1 if total is not
empty.
--diff Report changes only within line number ranges in the
unified diff provided on standard in by the user.
--exclude=patterns Comma-separated list of files or directories to
exclude.(Default:
.svn,CVS,.bzr,.hg,.git,__pycache__,.tox)
--filename=patterns Only check for filenames matching the patterns in this
comma-separated list. (Default: *.py)
--format=format Format errors according to the chosen formatter.
--hang-closing Hang closing bracket instead of matching indentation
of opening bracket's line.
--ignore=errors Comma-separated list of errors and warnings to ignore
(or skip). For example, ``--ignore=E4,E51,W234``.
(Default: E121,E123,E126,E226,E24,E704)
--extend-ignore=errors
Comma-separated list of errors and warnings to add to
the list of ignored ones. For example, ``--extend-
ignore=E4,E51,W234``.
--max-line-length=n Maximum allowed line length for the entirety of this
run. (Default: 79)
--select=errors Comma-separated list of errors and warnings to enable.
For example, ``--select=E4,E51,W234``. (Default: )
--disable-noqa Disable the effect of "# noqa". This will report
errors on lines with "# noqa" at the end.
--show-source Show the source generate each error or warning.
--statistics Count errors and warnings.
--enabled-extensions=ENABLED_EXTENSIONS
Enable plugins and extensions that are otherwise
disabled by default
--exit-zero Exit with status code "0" even if there are errors.
-j JOBS, --jobs=JOBS Number of subprocesses to use to run checks in
parallel. This is ignored on Windows. The default,
"auto", will auto-detect the number of processors
available to use. (Default: auto)
--output-file=OUTPUT_FILE
Redirect report to a file.
--tee Write to stdout and output-file.
--append-config=APPEND_CONFIG
Provide extra config files to parse in addition to the
files found by Flake8 by default. These files are the
last ones read and so they take the highest precedence
when multiple files provide the same option.
--config=CONFIG Path to the config file that will be the authoritative
config source. This will cause Flake8 to ignore all
other configuration files.
--isolated Ignore all configuration files.
--builtins=BUILTINS define more built-ins, comma separated
--doctests check syntax of the doctests
--include-in-doctest=INCLUDE_IN_DOCTEST
Run doctests only on these files
--exclude-from-doctest=EXCLUDE_FROM_DOCTEST
Skip these files when running doctests
Installed plugins: pyflakes: 1.0.0, pep8: 1.7.0