##// END OF EJS Templates
help: strip doctest from dochelp...
"Yann E. MORIN" -
r16250:684864d5 default
parent child Browse files
Show More
@@ -1,111 +1,116
1 1 # help.py - help data for mercurial
2 2 #
3 3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import gettext, _
9 9 import sys, os
10 10 import extensions, revset, fileset, templatekw, templatefilters, filemerge
11 11 import util
12 12
13 13 def listexts(header, exts, indent=1):
14 14 '''return a text listing of the given extensions'''
15 15 if not exts:
16 16 return ''
17 17 maxlength = max(len(e) for e in exts)
18 18 result = '\n%s\n\n' % header
19 19 for name, desc in sorted(exts.iteritems()):
20 20 result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
21 21 ':%s:' % name, desc)
22 22 return result
23 23
24 24 def extshelp():
25 25 doc = loaddoc('extensions')()
26 26 doc += listexts(_('enabled extensions:'), extensions.enabled())
27 27 doc += listexts(_('disabled extensions:'), extensions.disabled())
28 28 return doc
29 29
30 30 def loaddoc(topic):
31 31 """Return a delayed loader for help/topic.txt."""
32 32
33 33 def loader():
34 34 if util.mainfrozen():
35 35 module = sys.executable
36 36 else:
37 37 module = __file__
38 38 base = os.path.dirname(module)
39 39
40 40 for dir in ('.', '..'):
41 41 docdir = os.path.join(base, dir, 'help')
42 42 if os.path.isdir(docdir):
43 43 break
44 44
45 45 path = os.path.join(docdir, topic + ".txt")
46 46 doc = gettext(util.readfile(path))
47 47 for rewriter in helphooks.get(topic, []):
48 48 doc = rewriter(topic, doc)
49 49 return doc
50 50
51 51 return loader
52 52
53 53 helptable = sorted([
54 54 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
55 55 (["dates"], _("Date Formats"), loaddoc('dates')),
56 56 (["patterns"], _("File Name Patterns"), loaddoc('patterns')),
57 57 (['environment', 'env'], _('Environment Variables'),
58 58 loaddoc('environment')),
59 59 (['revs', 'revisions'], _('Specifying Single Revisions'),
60 60 loaddoc('revisions')),
61 61 (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
62 62 loaddoc('multirevs')),
63 63 (['revset', 'revsets'], _("Specifying Revision Sets"), loaddoc('revsets')),
64 64 (['fileset', 'filesets'], _("Specifying File Sets"), loaddoc('filesets')),
65 65 (['diffs'], _('Diff Formats'), loaddoc('diffs')),
66 66 (['merge-tools'], _('Merge Tools'), loaddoc('merge-tools')),
67 67 (['templating', 'templates'], _('Template Usage'),
68 68 loaddoc('templates')),
69 69 (['urls'], _('URL Paths'), loaddoc('urls')),
70 70 (["extensions"], _("Using additional features"), extshelp),
71 71 (["subrepo", "subrepos"], _("Subrepositories"), loaddoc('subrepos')),
72 72 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
73 73 (["glossary"], _("Glossary"), loaddoc('glossary')),
74 74 (["hgignore", "ignore"], _("syntax for Mercurial ignore files"),
75 75 loaddoc('hgignore')),
76 76 (["phases"], _("Working with Phases"), loaddoc('phases')),
77 77 ])
78 78
79 79 # Map topics to lists of callable taking the current topic help and
80 80 # returning the updated version
81 81 helphooks = {}
82 82
83 83 def addtopichook(topic, rewriter):
84 84 helphooks.setdefault(topic, []).append(rewriter)
85 85
86 86 def makeitemsdoc(topic, doc, marker, items):
87 87 """Extract docstring from the items key to function mapping, build a
88 88 .single documentation block and use it to overwrite the marker in doc
89 89 """
90 90 entries = []
91 91 for name in sorted(items):
92 92 text = (items[name].__doc__ or '').rstrip()
93 93 if not text:
94 94 continue
95 95 text = gettext(text)
96 96 lines = text.splitlines()
97 lines[1:] = [(' ' + l.strip()) for l in lines[1:]]
98 entries.append('\n'.join(lines))
97 doclines = [(lines[0])]
98 for l in lines[1:]:
99 # Stop once we find some Python doctest
100 if l.strip().startswith('>>>'):
101 break
102 doclines.append(' ' + l.strip())
103 entries.append('\n'.join(doclines))
99 104 entries = '\n\n'.join(entries)
100 105 return doc.replace(marker, entries)
101 106
102 107 def addtopicsymbols(topic, marker, symbols):
103 108 def add(topic, doc):
104 109 return makeitemsdoc(topic, doc, marker, symbols)
105 110 addtopichook(topic, add)
106 111
107 112 addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols)
108 113 addtopicsymbols('merge-tools', '.. internaltoolsmarker', filemerge.internals)
109 114 addtopicsymbols('revsets', '.. predicatesmarker', revset.symbols)
110 115 addtopicsymbols('templates', '.. keywordsmarker', templatekw.keywords)
111 116 addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters)
General Comments 0
You need to be logged in to leave comments. Login now