From b62edd334a4386e45aff52ad53a17c701dd89382 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 1 Jan 2022 19:26:43 -0500 Subject: [PATCH] fix extended_default_select from plugin loading --- src/flake8/options/manager.py | 3 ++- src/flake8/plugins/finder.py | 5 +++++ tests/integration/test_plugins.py | 1 + tests/unit/plugins/finder_test.py | 12 ++++++------ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index d3f6ec7..ad5543a 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -376,7 +376,8 @@ class OptionManager: _set_group(loaded.plugin.package) add_options(self) - self.extend_default_select(loaded.entry_name) + if loaded.plugin.entry_point.group == "flake8.extension": + self.extend_default_select([loaded.entry_name]) # isn't strictly necessary, but seems cleaner self._current_group = None diff --git a/src/flake8/plugins/finder.py b/src/flake8/plugins/finder.py index fcd6aff..6df0ccc 100644 --- a/src/flake8/plugins/finder.py +++ b/src/flake8/plugins/finder.py @@ -102,6 +102,11 @@ def _flake8_plugins( if ep.name == "F": yield Plugin(pyflakes_meta["name"], pyflakes_meta["version"], ep) elif ep.name.startswith("pycodestyle"): + # pycodestyle provides both `E` and `W` -- but our default select + # handles those + # ideally pycodestyle's plugin entrypoints would exactly represent + # the codes they produce... + ep = importlib_metadata.EntryPoint("E", ep.value, ep.group) yield Plugin( pycodestyle_meta["name"], pycodestyle_meta["version"], ep ) diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index e2c87e4..e7f2d38 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -95,6 +95,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.anopt == "foo" diff --git a/tests/unit/plugins/finder_test.py b/tests/unit/plugins/finder_test.py index f41aba4..0e5f81f 100644 --- a/tests/unit/plugins/finder_test.py +++ b/tests/unit/plugins/finder_test.py @@ -179,7 +179,7 @@ def test_flake8_plugins(flake8_dist, mock_distribution): "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.bare_except", + "E", "pycodestyle:bare_except", "flake8.extension", ), @@ -188,7 +188,7 @@ def test_flake8_plugins(flake8_dist, mock_distribution): "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.blank_lines", + "E", "pycodestyle:blank_lines", "flake8.extension", ), @@ -274,7 +274,7 @@ unrelated = unrelated:main "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.bare_except", + "E", "pycodestyle:bare_except", "flake8.extension", ), @@ -283,7 +283,7 @@ unrelated = unrelated:main "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.blank_lines", + "E", "pycodestyle:blank_lines", "flake8.extension", ), @@ -459,7 +459,7 @@ def test_find_plugins( "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.bare_except", + "E", "pycodestyle:bare_except", "flake8.extension", ), @@ -468,7 +468,7 @@ def test_find_plugins( "pycodestyle", "9000.2.0", importlib_metadata.EntryPoint( - "pycodestyle.blank_lines", + "E", "pycodestyle:blank_lines", "flake8.extension", ),