On Sat, 08 Oct 2016 17:22:26 +0200, liscju wrote: > # HG changeset patch > # User liscju <piotr.listkiew...@gmail.com> > # Date 1475926049 -7200 > # Sat Oct 08 13:27:29 2016 +0200 > # Node ID 5497a92be82db414f6913f869d5acd18b205cb2b > # Parent 91a3c58ecf938ed675f5364b88f0d663f12b0047 > help: show help content for disabled extension > > So far for disabled extension help showed only extension > summary. This commit makes help read content of the help > comments in extension module without actually loading > the module. > > diff --git a/mercurial/help.py b/mercurial/help.py > --- a/mercurial/help.py > +++ b/mercurial/help.py > @@ -7,6 +7,7 @@ > > from __future__ import absolute_import > > +import ast > import itertools > import os > import textwrap > @@ -300,6 +301,38 @@ addtopicsymbols('templates', '.. functio > addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands, > dedent=True) > > +def parsedisabledext(modname):
Have you tried the simpler way you pointed out? I said we could use ast since I didn't know that. https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-September/087972.html > + # return list of (command_name, command_module, command_doc) > + def finddisabledext(name): > + paths = extensions._disabledpaths() > + if name in paths: > + return paths[name] > + return None > + > + def iscmd(funast): > + for decorator in funast.decorator_list: > + if isinstance(decorator, ast.Call) and decorator.func.id == > 'command': > + return True > + return False > + > + def extractcmds(extast): > + return [funast.name for funast in extast.body if isinstance(funast, > ast.FunctionDef) and iscmd(funast)] > + > + def extractcmddoc(extast, cmd): > + funasts = [funast for funast in extast.body > + if isinstance(funast, ast.FunctionDef) and iscmd(funast) > and funast.name == cmd] > + if len(funasts) > 0: > + return ast.get_docstring(funasts[0]) > + else: > + return None > + > + extfile = open(finddisabledext(modname), 'r') > + try: > + extast = ast.parse(extfile.read()) > + return [(cmdname, modname, extractcmddoc(extast, cmdname)) for > cmdname in extractcmds(extast)] > + except SyntaxError: > + return [] Though we could provide the list of commands possibly defined by the disabled extension, I don't think that's necessary because that would complicate things. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel