Reputation: 1122
I'm trying to integrate a project with a flake8 plugin I wrote as a local plugin (not a PyPI package for example) as explained here. The project uses a virtual env, both locally and as a github workflow. Since flake8 is invoked from within the virtual env it can't find the plugin, which resides as a folder under the project root. When I manually add the plugin code to the virtual env folder it integrates nicely and flake8 is able to find to execute it.
The solution smells like some kind of github pre-commit-config/hook, but I can't find any reference in the docs for this usecase. Currently flake8 is configured in pre-commit-config like so:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: debug-statements
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: ['dlint']
Is there a way to use my non-packaged flake8 plugin with a virtual env locally / in a github workflow?
Upvotes: 1
Views: 887
Reputation: 1122
Turns out the paths
property was configured wrong and should have been
paths =
. flake8_plugins/
instead of
paths =
.flake8_plugins/
Upvotes: -1
Reputation: 69944
you'll want to configure paths
to make sure that flake8
puts the appropriate directories on sys.path
to discover your plugin
this is mentioned in the docs you linked, just a little bit further down:
However, if you are working on a project that isn’t set up as an installable package, or Flake8 doesn’t run from the same virtualenv your code runs in, you may need to tell Flake8 where to import your local plugins from. You can do this via the paths option in the local-plugins section of your config:
[flake8:local-plugins] extension = MC1 = myflake8plugin:MyChecker1 paths = ./path/to
note that if your local plugin has dependencies it needs, those will also be needed to be listed in additional_dependencies
in your pre-commit configuration
disclaimer: I'm the current flake8 maintainer, and I created pre-commit
Upvotes: 2