mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
Update to new entry_points selection protocol.
This commit is contained in:
parent
6de8252c03
commit
f4238018c0
5 changed files with 17 additions and 21 deletions
|
|
@ -47,7 +47,7 @@ install_requires=
|
||||||
typing; python_version<"3.5"
|
typing; python_version<"3.5"
|
||||||
configparser; python_version<"3.2"
|
configparser; python_version<"3.2"
|
||||||
functools32; python_version<"3.2"
|
functools32; python_version<"3.2"
|
||||||
importlib-metadata; python_version<"3.8"
|
importlib-metadata >= 3.6
|
||||||
|
|
||||||
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
|
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ if sys.version_info >= (3,): # pragma: no cover (PY3+)
|
||||||
else: # pragma: no cover (<PY3)
|
else: # pragma: no cover (<PY3)
|
||||||
from functools32 import lru_cache
|
from functools32 import lru_cache
|
||||||
|
|
||||||
if sys.version_info >= (3, 8): # pragma: no cover (PY38+)
|
if False: # pragma: no cover (PY??+)
|
||||||
import importlib.metadata as importlib_metadata
|
import importlib.metadata as importlib_metadata
|
||||||
else: # pragma: no cover (<PY38)
|
else: # pragma: no cover (<PY??)
|
||||||
import importlib_metadata
|
import importlib_metadata
|
||||||
|
|
||||||
__all__ = ("lru_cache", "importlib_metadata")
|
__all__ = ("lru_cache", "importlib_metadata")
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ class PluginManager(object): # pylint: disable=too-few-public-methods
|
||||||
|
|
||||||
def _load_entrypoint_plugins(self):
|
def _load_entrypoint_plugins(self):
|
||||||
LOG.info('Loading entry-points for "%s".', self.namespace)
|
LOG.info('Loading entry-points for "%s".', self.namespace)
|
||||||
eps = importlib_metadata.entry_points().get(self.namespace, ())
|
eps = importlib_metadata.entry_points(group=self.namespace)
|
||||||
# python2.7 occasionally gives duplicate results due to redundant
|
# python2.7 occasionally gives duplicate results due to redundant
|
||||||
# `local/lib` -> `../lib` symlink on linux in virtualenvs so we
|
# `local/lib` -> `../lib` symlink on linux in virtualenvs so we
|
||||||
# eliminate duplicates here
|
# eliminate duplicates here
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ def mock_file_checker_with_plugin(plugin_target):
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
importlib_metadata,
|
importlib_metadata,
|
||||||
'entry_points',
|
'entry_points',
|
||||||
return_value={'flake8.extension': [entry_point]},
|
return_value=[entry_point],
|
||||||
):
|
):
|
||||||
checks = manager.Checkers()
|
checks = manager.Checkers()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,21 @@ from flake8.plugins import manager
|
||||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||||
def test_calls_entrypoints_on_instantiation(entry_points_mck):
|
def test_calls_entrypoints_on_instantiation(entry_points_mck):
|
||||||
"""Verify that we call entry_points() when we create a manager."""
|
"""Verify that we call entry_points() when we create a manager."""
|
||||||
entry_points_mck.return_value = {}
|
entry_points_mck.return_value = []
|
||||||
manager.PluginManager(namespace='testing.entrypoints')
|
manager.PluginManager(namespace='testing.entrypoints')
|
||||||
entry_points_mck.assert_called_once_with()
|
entry_points_mck.assert_called_once_with(group='testing.entrypoints')
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||||
def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
|
def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
|
||||||
"""Verify that we create Plugins on instantiation."""
|
"""Verify that we create Plugins on instantiation."""
|
||||||
entry_points_mck.return_value = {
|
entry_points_mck.return_value = [
|
||||||
'testing.entrypoints': [
|
importlib_metadata.EntryPoint('T100', '', None),
|
||||||
importlib_metadata.EntryPoint('T100', '', None),
|
importlib_metadata.EntryPoint('T200', '', None),
|
||||||
importlib_metadata.EntryPoint('T200', '', None),
|
]
|
||||||
],
|
|
||||||
}
|
|
||||||
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
||||||
|
|
||||||
entry_points_mck.assert_called_once_with()
|
entry_points_mck.assert_called_once_with(group='testing.entrypoints')
|
||||||
assert 'T100' in plugin_mgr.plugins
|
assert 'T100' in plugin_mgr.plugins
|
||||||
assert 'T200' in plugin_mgr.plugins
|
assert 'T200' in plugin_mgr.plugins
|
||||||
assert isinstance(plugin_mgr.plugins['T100'], manager.Plugin)
|
assert isinstance(plugin_mgr.plugins['T100'], manager.Plugin)
|
||||||
|
|
@ -34,12 +32,10 @@ def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
|
||||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||||
def test_handles_mapping_functions_across_plugins(entry_points_mck):
|
def test_handles_mapping_functions_across_plugins(entry_points_mck):
|
||||||
"""Verify we can use the PluginManager call functions on all plugins."""
|
"""Verify we can use the PluginManager call functions on all plugins."""
|
||||||
entry_points_mck.return_value = {
|
entry_points_mck.return_value = [
|
||||||
'testing.entrypoints': [
|
importlib_metadata.EntryPoint('T100', '', None),
|
||||||
importlib_metadata.EntryPoint('T100', '', None),
|
importlib_metadata.EntryPoint('T200', '', None),
|
||||||
importlib_metadata.EntryPoint('T200', '', None),
|
]
|
||||||
],
|
|
||||||
}
|
|
||||||
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
||||||
plugins = [plugin_mgr.plugins[name] for name in plugin_mgr.names]
|
plugins = [plugin_mgr.plugins[name] for name in plugin_mgr.names]
|
||||||
|
|
||||||
|
|
@ -49,7 +45,7 @@ def test_handles_mapping_functions_across_plugins(entry_points_mck):
|
||||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||||
def test_local_plugins(entry_points_mck):
|
def test_local_plugins(entry_points_mck):
|
||||||
"""Verify PluginManager can load given local plugins."""
|
"""Verify PluginManager can load given local plugins."""
|
||||||
entry_points_mck.return_value = {}
|
entry_points_mck.return_value = []
|
||||||
plugin_mgr = manager.PluginManager(
|
plugin_mgr = manager.PluginManager(
|
||||||
namespace='testing.entrypoints',
|
namespace='testing.entrypoints',
|
||||||
local_plugins=['X = path.to:Plugin']
|
local_plugins=['X = path.to:Plugin']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue