我想爲類和函數名稱構建自定義格式器。Flake8無法在自定義格式器上加載插件「N8」
根據此doc它說,命名約定屬於N8**
警告代碼。
以下this教程與sublink的幫助後,這是由此得到的代碼
setup.py
from __future__ import with_statement
import setuptools
requires = [
"flake8 > 3.0.0",
]
setuptools.setup(
name="flake8_example",
license="MIT",
version="0.1.0",
description="our extension to flake8",
author="Me",
author_email="[email protected]",
url="https://gitlab.com/me/flake8_example",
packages=[
"flake8_example",
],
install_requires=requires,
entry_points={
'flake8.extension': [
'N8 = flake8_example:Example',
],
},
classifiers=[
"Framework :: Flake8",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Quality Assurance",
],
)
flake8_example.py
from flake8.formatting import base
class Example(base.BaseFormatter):
"""Flake8's example formatter."""
def format(self, error):
return 'Example formatter: {0!r}'.format(error)
我安裝它通過運行pip install --editable .
然後對其進行測試,我跑flake8 --format=example main.py
它拋出這個錯誤:如果你想寫一個格式化你需要閱讀的文件多一點
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "N8" due to 'module' object has no attribute 'Example'.