[PATCH] show full name of plugin in help

Martin Pool mbp at canonical.com
Wed Oct 4 05:02:02 BST 2006


On  3 Oct 2006, Alexander Belchenko <bialix at ukr.net> wrote:
> Attached patch provide support for show full name of plugin (plugin
> directory) in help even if it contains dot separated version number
> (e.g. myplug-1.2.3). With test, of course.
> 
> Also this test fixes cleanup after test in test_plugin_help_shows_plugin.

That sounds reasonable.

> === modified file bzrlib/commands.py // last-changed:bialix at ukr.net-20061003150
> ... 147-970c4b9b12a5e6b9
> --- bzrlib/commands.py
> +++ bzrlib/commands.py
> @@ -311,7 +311,14 @@
>          """
>          mod_parts = self.__module__.split('.')
>          if len(mod_parts) >= 3 and mod_parts[1] == 'plugins':
> -            return mod_parts[2]
> +            name = [mod_parts[2]]
> +            for m in mod_parts[3:]:
> +                try:
> +                    n = int(m)
> +                except ValueError:
> +                    break
> +                name.append(m)
> +            return '.'.join(name)
>          else:
>              return None

Why the int()/ValueError block?

> 
> === modified file bzrlib/tests/test_plugins.py
> --- bzrlib/tests/test_plugins.py
> +++ bzrlib/tests/test_plugins.py
> @@ -191,6 +191,33 @@
>              help = self.split_help_commands()['myplug']
>              self.assertContainsRe(help, '\[myplug\]')
>          finally:
> -            # remove the plugin 'plugin'
> -            if getattr(bzrlib.plugins, 'plugin', None):
> -                del bzrlib.plugins.plugin
> +            # unregister command
> +            if bzrlib.commands.plugin_cmds.get('myplug', None):
> +                del bzrlib.commands.plugin_cmds['myplug']
> +            # remove the plugin 'myplug'
> +            if getattr(bzrlib.plugins, 'myplug', None):
> +                delattr(bzrlib.plugins, 'myplug')
> +
> +    def test_plugin_help_shows_plugin_dotted_name(self):
> +        # Create a test plugin
> +        dir_ = 'plugin_test-1.2.3'
> +        os.mkdir(dir_)
> +        f = open(pathjoin(dir_, '__init__.py'), 'w')
> +        f.write(PLUGIN_TEXT)
> +        f.write('\nbzrlib.commands.register_command(cmd_myplug)\n')
> +        f.close()

Since your code changes Command, I think it would be a better test to
just check the behaviour of Command.plugin_name() instead, rather than
the help command.

-- 
Martin




More information about the bazaar mailing list