2017-02-23 7 views
1

클래스 및 함수 이름에 대한 사용자 정의 포맷터를 작성하려고합니다.Flake8이 사용자 정의 Formatter에서 "N8"플러그인을로드하지 못했습니다.

에 따르면이 doc에 따르면 명명 규칙은 N8** 경고 코드에 해당한다고합니다.

sublink의 도움으로 this 튜토리얼을 수행 한 후이

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) 

I 설정은 결과 코드를입니다를 실행하여3210

그런 다음 그것을 테스트 나는 flake8 --format=example main.py

을 실행 그것은이 오류가 발생합니다 : 당신이 좀 더 문서를 읽을 필요가 포맷터를 작성하려는 경우에 따라서

flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "N8" due to 'module' object has no attribute 'Example'.

답변

1

을 면밀히. 문서의 registering 섹션에서는 말한다 :

Flake8 presently looks at three groups:

  • flake8.extension
  • flake8.listen
  • flake8.report

If your plugin is one that adds checks to Flake8, you will use flake8.extension. If your plugin automatically fixes errors in code, you will use flake8.listen. Finally, if your plugin performs extra report handling (formatting, filtering, etc.) it will use flake8.report.

(강조 광산.)

setup.py은 다음과 같이해야 의미 :

entry_points = { 
    'flake8.report': [ 
     'example = flake8_example:Example', 
    ], 
} 

당신의 setup.py 제대로 다음 패키지를 설치하는 경우 달리기

flake8 --format=example ... 

잘 작동해야합니다. 그러나 예외는 모듈에 Example이라는 클래스가 없기 때문입니다. 당신의 setup.py가 적절하게 작동하지 않을 수 있습니다 이유로서

flake8_example/ 
    __init__.py 
    ... 

: 그것은처럼 보이도록 당신이 당신의 플러그인을 재구성해야하는 경우 packages은 하나의 파일 모듈을 선택할 것입니다 여부를 조사 또는한다.