I am trying to add my own flake8 plugin that lives in the same repository as the code I want to check, and follow the official documentation to do so. Further I have checked other stackoverflow threads for hints (How to use a local flake8 plugin with a python virtual env?), but without success.
I am stuck with the following error message: flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "local" due to No package metadata was found for plugin.plugin.
My repository structure looks like that:
.flake8
dev-scripts (from here I run flake8 in a venv created by poetry)
flake8-plugin
plugin
__init__.py
plugin.py (containing the class Plugin)
I have tried adding a setup.py
file to my flake8-plugin
folder, but it didn't change anything. And since I use the local-plugins
key in my configuration, I assume that I do not need a setup.py
.
.flake8:
...
[flake8:local-plugins]
# Code ('MR') must match the prefix of the error ids generated by the plugin, otherwise nothing will be reported:
extension =
MC = plugin.plugin:Plugin
paths =
./flake8-plugin/
plugin.py contains my Plugin class:
...
class Plugin:
name = __name__
version: str = importlib.metadata.version(__name__)
def __init__(self, tree: ast.AST):
self._tree = tree
def run(
self,
) -> typing.Generator[tuple[int, int, str, type[object]] , None, None]:
visitor = Visitor()
visitor.visit(self._tree)
for line, col, msg in visitor.errors:
print("error", flush=True)
yield line, col, msg, type(self)
Obviously I am missing something. What could it be?
- flake8 version: 5.0.4
- python version: CPython 3.10.6 on Linux