Merge "Document new way of registering local plugins"

This commit is contained in:
Zuul 2020-04-04 22:57:35 +00:00 committed by Gerrit Code Review
commit f8a57d6583
1 changed files with 28 additions and 14 deletions

View File

@ -114,24 +114,38 @@ For example to enable H106 and H203:
Local Checks Local Checks
============ ============
hacking supports having local changes in a source tree. They can be configured hacking supports having local changes in a source tree. They need to
to run in two different ways. They can be registered individually, or with be registered individually in tox.ini:
a factory function.
For individual registration, put a comma separated list of pep8 compatible Add to tox.ini a new section `flake8:local-plugins` and list each plugin with
check functions into the hacking section of tox.ini. E.g.: its entry-point. Additionally, you can add the path to the files
containing the plugins so that the repository does not need to be
installed with the `paths` directive.
.. code-block:: ini .. code-block:: ini
[hacking] [flake8:local-plugins]
local-check = nova.tests.hacking.bad_code_is_terrible extension =
N307 = checks:import_no_db_in_virt
N325 = checks:CheckForStrUnicodeExc
paths =
./nova/hacking
Alternately, you can specify the location of a callable that will be called The plugins, in the example above they live in
at registration time and will be passed the registration function. The callable `nova/hacking/checks.py`, need to annotate all functions with `@core.flake8ext`
should expect to call the passed in function on everything if wants to
register. Such as:
.. code-block:: ini .. code-block:: python
[hacking] from hacking import core
local-check-factory = nova.tests.hacking.factory ...
@core.flake8ext
def import_no_db_in_virt(logical_line, filename):
...
class CheckForStrUnicodeExc(BaseASTChecker):
name = "check_for_str_unicode_exc"
version = "1.0"
...
Further details are part of the `flake8 documentation
<https://flake8.pycqa.org/en/latest/plugin-development/index.html>`_.