mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-06 21:16:54 +00:00
Merge branch 'feature/importlib-metadata-entrypoints-select' into 'master'
Update entry_points to new select-based API See merge request pycqa/flake8!464
This commit is contained in:
commit
9ce80a7454
5 changed files with 20 additions and 28 deletions
|
|
@ -47,7 +47,7 @@ install_requires=
|
|||
typing; python_version<"3.5"
|
||||
configparser; 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.*
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,4 @@ if sys.version_info >= (3,): # pragma: no cover (PY3+)
|
|||
else: # pragma: no cover (<PY3)
|
||||
from functools32 import lru_cache
|
||||
|
||||
if sys.version_info >= (3, 8): # pragma: no cover (PY38+)
|
||||
import importlib.metadata as importlib_metadata
|
||||
else: # pragma: no cover (<PY38)
|
||||
import importlib_metadata
|
||||
|
||||
__all__ = ("lru_cache", "importlib_metadata")
|
||||
__all__ = ("lru_cache",)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
import logging
|
||||
from typing import Any, Dict, List, Optional, Set
|
||||
|
||||
import importlib_metadata
|
||||
|
||||
from flake8 import exceptions
|
||||
from flake8 import utils
|
||||
from flake8._compat import importlib_metadata
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -251,7 +252,7 @@ class PluginManager(object): # pylint: disable=too-few-public-methods
|
|||
|
||||
def _load_entrypoint_plugins(self):
|
||||
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
|
||||
# `local/lib` -> `../lib` symlink on linux in virtualenvs so we
|
||||
# eliminate duplicates here
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
"""Integration tests for the checker submodule."""
|
||||
import mock
|
||||
import pytest
|
||||
import importlib_metadata
|
||||
|
||||
from flake8 import checker
|
||||
from flake8._compat import importlib_metadata
|
||||
from flake8.plugins import manager
|
||||
from flake8.processor import FileProcessor
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ def mock_file_checker_with_plugin(plugin_target):
|
|||
with mock.patch.object(
|
||||
importlib_metadata,
|
||||
'entry_points',
|
||||
return_value={'flake8.extension': [entry_point]},
|
||||
return_value=[entry_point],
|
||||
):
|
||||
checks = manager.Checkers()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,28 @@
|
|||
"""Tests for flake8.plugins.manager.PluginManager."""
|
||||
import mock
|
||||
import importlib_metadata
|
||||
|
||||
from flake8._compat import importlib_metadata
|
||||
from flake8.plugins import manager
|
||||
|
||||
|
||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||
def test_calls_entrypoints_on_instantiation(entry_points_mck):
|
||||
"""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')
|
||||
entry_points_mck.assert_called_once_with()
|
||||
entry_points_mck.assert_called_once_with(group='testing.entrypoints')
|
||||
|
||||
|
||||
@mock.patch.object(importlib_metadata, 'entry_points')
|
||||
def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
|
||||
"""Verify that we create Plugins on instantiation."""
|
||||
entry_points_mck.return_value = {
|
||||
'testing.entrypoints': [
|
||||
importlib_metadata.EntryPoint('T100', '', None),
|
||||
importlib_metadata.EntryPoint('T200', '', None),
|
||||
],
|
||||
}
|
||||
entry_points_mck.return_value = [
|
||||
importlib_metadata.EntryPoint('T100', '', None),
|
||||
importlib_metadata.EntryPoint('T200', '', None),
|
||||
]
|
||||
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 'T200' in plugin_mgr.plugins
|
||||
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')
|
||||
def test_handles_mapping_functions_across_plugins(entry_points_mck):
|
||||
"""Verify we can use the PluginManager call functions on all plugins."""
|
||||
entry_points_mck.return_value = {
|
||||
'testing.entrypoints': [
|
||||
importlib_metadata.EntryPoint('T100', '', None),
|
||||
importlib_metadata.EntryPoint('T200', '', None),
|
||||
],
|
||||
}
|
||||
entry_points_mck.return_value = [
|
||||
importlib_metadata.EntryPoint('T100', '', None),
|
||||
importlib_metadata.EntryPoint('T200', '', None),
|
||||
]
|
||||
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
||||
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')
|
||||
def test_local_plugins(entry_points_mck):
|
||||
"""Verify PluginManager can load given local plugins."""
|
||||
entry_points_mck.return_value = {}
|
||||
entry_points_mck.return_value = []
|
||||
plugin_mgr = manager.PluginManager(
|
||||
namespace='testing.entrypoints',
|
||||
local_plugins=['X = path.to:Plugin']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue