我试图按照教程Building a custom Flake8 plugin \| Dunderdoc学习构建Flake8插件
完成本教程后,我得到了如下设置和检查程序文件:
setup.py
import setuptools
setuptools.setup(
name='flake8-picky',
license='MIT',
version='0.0.1',
description='Plugin to comply with my picky standards',
author='Valdir Stumm Junior',
author_email='stummjr@gmail.com',
url='http://github.com/stummjr/flake8-picky',
py_modules=['flake8_picky'],
entry_points={
'flake8.extension': [
'PCK0 = picky_checker:PickyChecker',
],
},
install_requires=['flake8'],
classifiers=[
'Topic :: Software Development :: Quality Assurance',
],
)
挑剔的棋盘格.py
import ast
class ForbiddenFunctionsFinder(ast.NodeVisitor):
forbidden = ['map', 'filter']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.issues = []
def visit_Call(self, node):
if not isinstance(node.func, ast.Name):
return
if node.func.id in self.forbidden:
msg = "PCK01 Please don't use {}()".format(node.func.id)
self.issues.append((node.lineno, node.col_offset, msg))
class PickyChecker(object):
options = None
name = 'picky_checker'
version = '0.1'
def __init__(self, tree, filename):
self.tree = tree
self.filename = filename
def run(self):
parser = ForbiddenFunctionsFinder()
parser.visit(self.tree)
for lineno, column, msg in parser.issues:
yield (lineno, column, msg, PickyChecker)
示例.py
data = list(range(100))
x = map(lambda x: 2 * x, data)
print(x)
y = filter(lambda x: x % 2 == 0, data)
print(y)
成功完成插件安装后,我运行命令flake8 example.py
,并出现以下错误:
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "PCK0" due to No module named picky_checker.
什么是错误?我如何修复它?谢谢
您的setup.py格式不正确,不包含您选择的软件包
应该是
否则,setuptools将不会在生成/安装的结果包中包含您的模块
另一方面,最好的做法是将模块名与包匹配(当然不是必需的),因此我将把模块重命名为
flake8_picky.py
,而不是更改setup.py
)相关问题 更多 >
编程相关推荐