Github: https://github.com/PyCQA/pycodestyle
pycodestyle(旧称pep8) – Pythonスタイルのガイドチェッカー
pycodestyleは、 PEP 8のスタイル規則のいくつかに対してPythonコードをチェックするためのツールです。
注意
このパッケージは以前はpep8
と呼ばれていpep8
たが、混乱をpycodestyle
ためpycodestyle
に改名されpycodestyle
た。 さらなる議論は、Guidoがこの変更を要求した問題 、または@ IanLee1521によるPyCon 2016の落雷の話で見つけることができます: スライド ビデオ 。
特徴
- プラグインのアーキテクチャ:新しいチェックを追加するのは簡単です。
- 解析可能な出力:エディタのエラー位置にジャンプします。
- Small:ちょうど1つのPythonファイルで、stdlibだけが必要です。 この目的のために
pycodestyle.py
ファイルだけを使うことができます。 - 包括的なテストスイートが付属しています。
インストール
pycodestyle.py
インストール、アップグレード、およびアンインストールは、次のコマンドで行うことができます。
$ pip install pycodestyle $ pip install --upgrade pycodestyle $ pip uninstall pycodestyle
Debian / Ubuntuのパッケージもありますが、必ずしも最新バージョンとは限りません。
使用例と出力例
$ pycodestyle --first optparse.py optparse.py:69:11: E401 multiple imports on one line optparse.py:77:1: E302 expected 2 blank lines, found 1 optparse.py:88:5: E301 expected 1 blank line, found 0 optparse.py:222:34: W602 deprecated form of raising exception optparse.py:347:31: E211 whitespace before '(' optparse.py:357:17: E201 whitespace after '{' optparse.py:472:29: E221 multiple spaces before operator optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
pycodestyle.py
エラーごとのソースコードを表示させることもできますし、PEP 8の関連テキストも表示することができます:
$ pycodestyle --show-source --show-pep8 testsuite/E40.py testsuite/E40.py:2:10: E401 multiple imports on one line import os, sys ^ Imports should usually be on separate lines. Okay: import os\nimport sys E401: import sys, os
または、各エラーが検出された頻度を表示することもできます。
$ pycodestyle --statistics -qq Python-2.5/Lib 232 E201 whitespace after '[' 599 E202 whitespace before ')' 631 E203 whitespace before ',' 842 E211 whitespace before '(' 2531 E221 multiple spaces before operator 4473 E301 expected 1 blank line, found 0 4006 E302 expected 2 blank lines, found 1 165 E303 too many blank lines (4) 325 E401 multiple imports on one line 3615 E501 line too long (82 characters) 612 W601 .has_key() is deprecated, use 'in' 1188 W602 deprecated form of raising exception