diff options
| author | Anthony Sottile <asottile@umich.edu> | 2018-11-21 17:28:55 +0000 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2018-11-21 17:28:55 +0000 |
| commit | b3f205a936c8e7d3e3866b417f44872f8bf4ad2c (patch) | |
| tree | 9a8f7c13002019254f166cb45c929fb424028848 /src/flake8 | |
| parent | cd75e4e2b2f72b585d6eaf75dd9b3afe4ecdb925 (diff) | |
| parent | ff15ba0865c396688ac3254b6401beed501496f4 (diff) | |
| download | flake8-b3f205a936c8e7d3e3866b417f44872f8bf4ad2c.tar.gz | |
Merge branch 'entrypoints' into 'master'
Replace setuptools with entrypoints
See merge request pycqa/flake8!264
Diffstat (limited to 'src/flake8')
| -rw-r--r-- | src/flake8/main/application.py | 13 | ||||
| -rw-r--r-- | src/flake8/main/debug.py | 7 | ||||
| -rw-r--r-- | src/flake8/plugins/manager.py | 30 |
3 files changed, 15 insertions, 35 deletions
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index b86b3cc..86d7fd4 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -169,7 +169,7 @@ class Application(object): If :attr:`check_plugins`, :attr:`listening_plugins`, or :attr:`formatting_plugins` are ``None`` then this method will update them with the appropriate plugin manager instance. Given the expense - of finding plugins (via :mod:`pkg_resources`) we want this to be + of finding plugins (via :mod:`entrypoints`) we want this to be idempotent and so only update those attributes if they are ``None``. """ if self.local_plugins is None: @@ -238,16 +238,7 @@ class Application(object): def formatter_for(self, formatter_plugin_name): """Retrieve the formatter class by plugin name.""" - try: - default_formatter = self.formatting_plugins["default"] - except KeyError: - raise exceptions.ExecutionError( - "The 'default' Flake8 formatting plugin is unavailable. " - "This usually indicates that your setuptools is too old. " - "Please upgrade setuptools. If that does not fix the issue" - " please file an issue." - ) - + default_formatter = self.formatting_plugins["default"] formatter_plugin = self.formatting_plugins.get(formatter_plugin_name) if formatter_plugin is None: LOG.warning( diff --git a/src/flake8/main/debug.py b/src/flake8/main/debug.py index 51bac9a..e02da6b 100644 --- a/src/flake8/main/debug.py +++ b/src/flake8/main/debug.py @@ -4,6 +4,8 @@ from __future__ import print_function import json import platform +import entrypoints + def print_information( option, option_string, value, parser, option_manager=None @@ -64,7 +66,4 @@ def plugins_from(option_manager): def dependencies(): """Generate the list of dependencies we care about.""" - # defer this expensive import, not used outside --bug-report - import setuptools - - return [{"dependency": "setuptools", "version": setuptools.__version__}] + return [{"dependency": "entrypoints", "version": entrypoints.__version__}] diff --git a/src/flake8/plugins/manager.py b/src/flake8/plugins/manager.py index 6d0cf99..010cfb9 100644 --- a/src/flake8/plugins/manager.py +++ b/src/flake8/plugins/manager.py @@ -2,7 +2,7 @@ import logging import sys -import pkg_resources +import entrypoints from flake8 import exceptions from flake8 import utils @@ -143,17 +143,8 @@ class Plugin(object): r"""Call the plugin with \*args and \*\*kwargs.""" return self.plugin(*args, **kwargs) # pylint: disable=not-callable - def _load(self, verify_requirements): - # Avoid relying on hasattr() here. - resolve = getattr(self.entry_point, "resolve", None) - require = getattr(self.entry_point, "require", None) - if resolve and require: - if verify_requirements: - LOG.debug('Verifying plugin "%s"\'s requirements.', self.name) - require() - self._plugin = resolve() - else: - self._plugin = self.entry_point.load(require=verify_requirements) + def _load(self): + self._plugin = self.entry_point.load() if not callable(self._plugin): msg = ( "Plugin %r is not a callable. It might be written for an" @@ -171,15 +162,14 @@ class Plugin(object): cached plugin. :param bool verify_requirements: - Whether or not to make setuptools verify that the requirements for - the plugin are satisfied. + Does nothing, retained for backwards compatibility. :returns: Nothing """ if self._plugin is None: LOG.info('Loading plugin "%s" from entry-point.', self.name) try: - self._load(verify_requirements) + self._load() except Exception as load_exception: LOG.exception(load_exception) failed_to_load = exceptions.FailedToLoadPlugin( @@ -256,11 +246,9 @@ class PluginManager(object): # pylint: disable=too-few-public-methods :param list local_plugins: Plugins from config (as "X = path.to:Plugin" strings). :param bool verify_requirements: - Whether or not to make setuptools verify that the requirements for - the plugin are satisfied. + Does nothing, retained for backwards compatibility. """ self.namespace = namespace - self.verify_requirements = verify_requirements self.plugins = {} self.names = [] self._load_local_plugins(local_plugins or []) @@ -273,12 +261,14 @@ class PluginManager(object): # pylint: disable=too-few-public-methods Plugins from config (as "X = path.to:Plugin" strings). """ for plugin_str in local_plugins: - entry_point = pkg_resources.EntryPoint.parse(plugin_str) + name, _, entry_str = plugin_str.partition("=") + name, entry_str = name.strip(), entry_str.strip() + entry_point = entrypoints.EntryPoint.from_string(entry_str, name) self._load_plugin_from_entrypoint(entry_point, local=True) def _load_entrypoint_plugins(self): LOG.info('Loading entry-points for "%s".', self.namespace) - for entry_point in pkg_resources.iter_entry_points(self.namespace): + for entry_point in entrypoints.get_group_all(self.namespace): self._load_plugin_from_entrypoint(entry_point) def _load_plugin_from_entrypoint(self, entry_point, local=False): |
