pregenerate the pycodestyle plugin to avoid call overhead

This commit is contained in:
Anthony Sottile 2022-01-25 13:30:36 -05:00
parent 1e5f861c52
commit 4e56fc0f6a
5 changed files with 255 additions and 37 deletions

View file

@ -104,7 +104,7 @@ def test_local_plugin_can_add_option(local_config):
args = aggregator.aggregate_options(option_manager, cfg, cfg_dir, argv)
assert args.extended_default_select == {"XE", "F", "E", "C90"}
assert args.extended_default_select == {"XE", "F", "E", "W", "C90"}
assert args.anopt == "foo"

View file

@ -0,0 +1,33 @@
import importlib.machinery
import importlib.util
import os.path
import flake8.plugins.pycodestyle
HERE = os.path.dirname(os.path.abspath(__file__))
def test_up_to_date():
"""Validate that the generated pycodestyle plugin is up to date.
We generate two "meta" plugins for pycodestyle to avoid calling overhead.
To regenerate run:
./bin/gen-pycodestyle-plugin > src/flake8/plugins/pycodestyle.py
"""
path = os.path.join(HERE, "../../../bin/gen-pycodestyle-plugin")
name = os.path.basename(path)
loader = importlib.machinery.SourceFileLoader(name, path)
spec = importlib.util.spec_from_loader(loader.name, loader)
assert spec is not None
mod = importlib.util.module_from_spec(spec)
loader.exec_module(mod)
expected = "".join(f"{line}\n" for line in mod.lines())
with open(flake8.plugins.pycodestyle.__file__) as f:
contents = f.read()
assert contents == expected