[PATCH 2 of 2] version: add extensions version info (issue4209)

Augie Fackler lists at durin42.com
Tue Jun 10 08:57:28 CDT 2014


On Tue, Jun 10, 2014 at 7:57 AM, anatoly techtonik <techtonik at gmail.com>
wrote:

> # HG changeset patch
> # User anatoly techtonik <techtonik at gmail.com>
> # Date 1402401369 -10800
> #      Tue Jun 10 14:56:09 2014 +0300
> # Branch stable
> # Node ID 917c6c9356d47f3d3a97ca45967a1f91813c771a
> # Parent  bd3150aeb5949c8ca2304bf52c6206730b73a8f9
> version: add extensions version info (issue4209)
>
> Query extensions for version info and format nicely into columns
>
> diff -r bd3150aeb594 -r 917c6c9356d4 mercurial/commands.py
> --- a/mercurial/commands.py     Tue Jun 10 13:44:37 2014 +0300
> +++ b/mercurial/commands.py     Tue Jun 10 14:56:09 2014 +0300
> @@ -14,6 +14,7 @@
>  import patch, help, encoding, templatekw, discovery
>  import archival, changegroup, cmdutil, hbisect
>  import sshserver, hgweb, commandserver
> +from extensions import extensions


I'm a /little/ worried this might lead to import cycles with extensions,
but I think I've talked myself out of that because of how extension loading
happens.


>  from hgweb import server as hgweb_server
>  import merge as mergemod
>  import minirst, revset, fileset
> @@ -5908,6 +5909,29 @@
>      """
>      return hg.verify(repo)
>
> +
> +def moduleversion(module):
> +    """gets version information from the module
> +
> +    This code was inspired by Django Debug Toolbar's VersionDebugPanel.
> +    """
> +    extension = module
> +    if hasattr(extension, 'get_version'):
> +        get_version = extension.get_version
> +        if callable(get_version):
> +            version = get_version()
> +        else:
> +            version = get_version
> +    elif hasattr(extension, 'VERSION'):
>

Use mercurial.util.safehasattr. See
http://doc.bazaar.canonical.com/developers/code-style.html#hasattr-and-getattr
for why.

Also, make sure to run 'make test-check-code-hg.t' which should have warned
you about this.


> +        version = extension.VERSION
> +    elif hasattr(extension, '__version__'):
> +        version = extension.__version__
> +    else:
> +        version = ''
> +    if isinstance(version, (list, tuple)):
> +        version = '.'.join(str(o) for o in version)
> +    return version
> +
>  @command('version', [])
>  def version_(ui):
>      """output version and copyright information"""
> @@ -5930,8 +5954,14 @@
>      # by Markus Zapke-Gruendemann <info at keimlink.de>
>      ui.note(_("\nEnabled extensions:\n\n"))
>      if ui.verbose:
> -        for name, module in ui.configitems('extensions'):
> -            ui.write("  %s\n" % name)
> +        names = []
> +        vers = []
> +        for name, module in extensions():
> +            names.append(name)
> +            vers.append(moduleversion(module))
> +        maxnamelen = max(len(n) for n in names)
> +        for i,n in enumerate(names):
> +            ui.write("  %s  %s\n" % (n.ljust(maxnamelen), vers[i]))
>

Not sure how others would feel, but you could probably make a rst table and
then render it with minirst to avoid some of this hand formatting.


>
>
>  norepo = ("clone init version help debugcommands debugcomplete"
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140610/5c7e6ece/attachment.html>


More information about the Mercurial-devel mailing list