From 18c0b14b5ca84b0cf9f64aa211494dba1e5c3c51 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Sun, 6 Aug 2017 20:57:04 -0700 Subject: [PATCH] Append [local] to version of local plugins. --- src/flake8/plugins/manager.py | 15 +++++++++++---- tests/unit/test_plugin.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/flake8/plugins/manager.py b/src/flake8/plugins/manager.py index 55b01d2..699b1aa 100644 --- a/src/flake8/plugins/manager.py +++ b/src/flake8/plugins/manager.py @@ -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) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 84f676a..d6bc27f 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -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