mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 12:16:53 +00:00
Append [local] to version of local plugins.
This commit is contained in:
parent
2cadc060d3
commit
18c0b14b5c
2 changed files with 22 additions and 4 deletions
|
|
@ -24,7 +24,7 @@ NO_GROUP_FOUND = object()
|
|||
class Plugin(object):
|
||||
"""Wrap an EntryPoint from setuptools and other logic."""
|
||||
|
||||
def __init__(self, name, entry_point):
|
||||
def __init__(self, name, entry_point, local=False):
|
||||
"""Initialize our Plugin.
|
||||
|
||||
:param str name:
|
||||
|
|
@ -33,9 +33,12 @@ class Plugin(object):
|
|||
EntryPoint returned by setuptools.
|
||||
:type entry_point:
|
||||
setuptools.EntryPoint
|
||||
:param bool local:
|
||||
Is this a repo-local plugin?
|
||||
"""
|
||||
self.name = name
|
||||
self.entry_point = entry_point
|
||||
self.local = local
|
||||
self._plugin = None
|
||||
self._parameters = None
|
||||
self._parameter_names = None
|
||||
|
|
@ -112,6 +115,8 @@ class Plugin(object):
|
|||
self._version = version_for(self)
|
||||
else:
|
||||
self._version = self.plugin.version
|
||||
if self.local:
|
||||
self._version += ' [local]'
|
||||
|
||||
return self._version
|
||||
|
||||
|
|
@ -263,21 +268,23 @@ class PluginManager(object): # pylint: disable=too-few-public-methods
|
|||
"""
|
||||
for plugin_str in local_plugins:
|
||||
entry_point = pkg_resources.EntryPoint.parse(plugin_str)
|
||||
self._load_plugin_from_entrypoint(entry_point)
|
||||
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):
|
||||
self._load_plugin_from_entrypoint(entry_point)
|
||||
|
||||
def _load_plugin_from_entrypoint(self, entry_point):
|
||||
def _load_plugin_from_entrypoint(self, entry_point, local=False):
|
||||
"""Load a plugin from a setuptools EntryPoint.
|
||||
|
||||
:param EntryPoint entry_point:
|
||||
EntryPoint to load plugin from.
|
||||
:param bool local:
|
||||
Is this a repo-local plugin?
|
||||
"""
|
||||
name = entry_point.name
|
||||
self.plugins[name] = Plugin(name, entry_point)
|
||||
self.plugins[name] = Plugin(name, entry_point, local=local)
|
||||
self.names.append(name)
|
||||
LOG.debug('Loaded %r for plugin "%s".', self.plugins[name], name)
|
||||
|
||||
|
|
|
|||
|
|
@ -111,6 +111,17 @@ def test_version_proxies_to_the_plugin():
|
|||
assert plugin.version == 'a.b.c'
|
||||
|
||||
|
||||
def test_local_plugin_version():
|
||||
"""Verify that local plugins have [local] appended to version."""
|
||||
entry_point = mock.Mock(spec=['require', 'resolve', 'load'])
|
||||
plugin_obj = mock.Mock(spec_set=['version'])
|
||||
plugin_obj.version = 'a.b.c'
|
||||
plugin = manager.Plugin('T000', entry_point, local=True)
|
||||
plugin._plugin = plugin_obj
|
||||
|
||||
assert plugin.version == 'a.b.c [local]'
|
||||
|
||||
|
||||
def test_register_options():
|
||||
"""Verify we call add_options on the plugin only if it exists."""
|
||||
# Set up our mocks and Plugin object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue