comparison mercurial/help.py @ 32638:c9318beb7c1a

py3: convert __doc__ back to bytes in help.py pycompat.getdoc() is pretty simple, but we wouldn't want to write handling of None inline.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 01 Jun 2017 22:24:15 +0900
parents 1b90036f42f0
children d110fb58424c
comparison
equal deleted inserted replaced
32637:4b426ae96ff2 32638:c9318beb7c1a
138 if len(entry) == 3: 138 if len(entry) == 3:
139 summary = entry[2] 139 summary = entry[2]
140 else: 140 else:
141 summary = '' 141 summary = ''
142 # translate docs *before* searching there 142 # translate docs *before* searching there
143 docs = _(getattr(entry[0], '__doc__', None)) or '' 143 docs = _(pycompat.getdoc(entry[0])) or ''
144 if kw in cmd or lowercontains(summary) or lowercontains(docs): 144 if kw in cmd or lowercontains(summary) or lowercontains(docs):
145 doclines = docs.splitlines() 145 doclines = docs.splitlines()
146 if doclines: 146 if doclines:
147 summary = doclines[0] 147 summary = doclines[0]
148 cmdname = cmd.partition('|')[0].lstrip('^') 148 cmdname = cmd.partition('|')[0].lstrip('^')
160 # extension docs are already translated 160 # extension docs are already translated
161 results['extensions'].append((name, docs.splitlines()[0])) 161 results['extensions'].append((name, docs.splitlines()[0]))
162 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems(): 162 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
163 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): 163 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
164 cmdname = cmd.partition('|')[0].lstrip('^') 164 cmdname = cmd.partition('|')[0].lstrip('^')
165 if entry[0].__doc__: 165 cmddoc = pycompat.getdoc(entry[0])
166 cmddoc = gettext(entry[0].__doc__).splitlines()[0] 166 if cmddoc:
167 cmddoc = gettext(cmddoc).splitlines()[0]
167 else: 168 else:
168 cmddoc = _('(no help text available)') 169 cmddoc = _('(no help text available)')
169 if filtercmd(ui, cmdname, kw, cmddoc): 170 if filtercmd(ui, cmdname, kw, cmddoc):
170 continue 171 continue
171 results['extensioncommands'].append((cmdname, cmddoc)) 172 results['extensioncommands'].append((cmdname, cmddoc))
257 """Extract docstring from the items key to function mapping, build a 258 """Extract docstring from the items key to function mapping, build a
258 single documentation block and use it to overwrite the marker in doc. 259 single documentation block and use it to overwrite the marker in doc.
259 """ 260 """
260 entries = [] 261 entries = []
261 for name in sorted(items): 262 for name in sorted(items):
262 text = (items[name].__doc__ or '').rstrip() 263 text = (pycompat.getdoc(items[name]) or '').rstrip()
263 if (not text 264 if (not text
264 or not ui.verbose and any(w in text for w in _exclkeywords)): 265 or not ui.verbose and any(w in text for w in _exclkeywords)):
265 continue 266 continue
266 text = gettext(text) 267 text = gettext(text)
267 if dedent: 268 if dedent:
343 if full and not ui.quiet and len(aliases) > 1: 344 if full and not ui.quiet and len(aliases) > 1:
344 rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:])) 345 rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:]))
345 rst.append('\n') 346 rst.append('\n')
346 347
347 # description 348 # description
348 doc = gettext(entry[0].__doc__) 349 doc = gettext(pycompat.getdoc(entry[0]))
349 if not doc: 350 if not doc:
350 doc = _("(no help text available)") 351 doc = _("(no help text available)")
351 if util.safehasattr(entry[0], 'definition'): # aliased command 352 if util.safehasattr(entry[0], 'definition'): # aliased command
352 source = entry[0].source 353 source = entry[0].source
353 if entry[0].definition.startswith('!'): # shell alias 354 if entry[0].definition.startswith('!'): # shell alias
365 366
366 # check if this command shadows a non-trivial (multi-line) 367 # check if this command shadows a non-trivial (multi-line)
367 # extension help text 368 # extension help text
368 try: 369 try:
369 mod = extensions.find(name) 370 mod = extensions.find(name)
370 doc = gettext(mod.__doc__) or '' 371 doc = gettext(pycompat.getdoc(mod)) or ''
371 if '\n' in doc.strip(): 372 if '\n' in doc.strip():
372 msg = _("(use 'hg help -e %s' to show help for " 373 msg = _("(use 'hg help -e %s' to show help for "
373 "the %s extension)") % (name, name) 374 "the %s extension)") % (name, name)
374 rst.append('\n%s\n' % msg) 375 rst.append('\n%s\n' % msg)
375 except KeyError: 376 except KeyError:
413 e[0].__module__ != commands.__name__): 414 e[0].__module__ != commands.__name__):
414 continue 415 continue
415 if name == "shortlist" and not f.startswith("^"): 416 if name == "shortlist" and not f.startswith("^"):
416 continue 417 continue
417 f = f.lstrip("^") 418 f = f.lstrip("^")
418 doc = e[0].__doc__ 419 doc = pycompat.getdoc(e[0])
419 if filtercmd(ui, f, name, doc): 420 if filtercmd(ui, f, name, doc):
420 continue 421 continue
421 doc = gettext(doc) 422 doc = gettext(doc)
422 if not doc: 423 if not doc:
423 doc = _("(no help text available)") 424 doc = _("(no help text available)")
516 return rst 517 return rst
517 518
518 def helpext(name, subtopic=None): 519 def helpext(name, subtopic=None):
519 try: 520 try:
520 mod = extensions.find(name) 521 mod = extensions.find(name)
521 doc = gettext(mod.__doc__) or _('no help text available') 522 doc = gettext(pycompat.getdoc(mod)) or _('no help text available')
522 except KeyError: 523 except KeyError:
523 mod = None 524 mod = None
524 doc = extensions.disabledext(name) 525 doc = extensions.disabledext(name)
525 if not doc: 526 if not doc:
526 raise error.UnknownCommand(name) 527 raise error.UnknownCommand(name)
552 return rst 553 return rst
553 554
554 def helpextcmd(name, subtopic=None): 555 def helpextcmd(name, subtopic=None):
555 cmd, ext, mod = extensions.disabledcmd(ui, name, 556 cmd, ext, mod = extensions.disabledcmd(ui, name,
556 ui.configbool('ui', 'strict')) 557 ui.configbool('ui', 'strict'))
557 doc = gettext(mod.__doc__).splitlines()[0] 558 doc = gettext(pycompat.getdoc(mod)).splitlines()[0]
558 559
559 rst = listexts(_("'%s' is provided by the following " 560 rst = listexts(_("'%s' is provided by the following "
560 "extension:") % cmd, {ext: doc}, indent=4, 561 "extension:") % cmd, {ext: doc}, indent=4,
561 showdeprecated=True) 562 showdeprecated=True)
562 rst.append('\n') 563 rst.append('\n')