Mercurial > hg
comparison mercurial/help.py @ 14317:660b0c1b6196
extensions: move moduledoc to break import loop with help
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 13 May 2011 11:04:51 -0500 |
parents | d5b525697ddb |
children | 1f46be4689ed |
comparison
equal
deleted
inserted
replaced
14316:d5b525697ddb | 14317:660b0c1b6196 |
---|---|
7 | 7 |
8 from i18n import gettext, _ | 8 from i18n import gettext, _ |
9 import sys, os | 9 import sys, os |
10 import extensions | 10 import extensions |
11 import util | 11 import util |
12 | |
13 | |
14 def moduledoc(file): | |
15 '''return the top-level python documentation for the given file | |
16 | |
17 Loosely inspired by pydoc.source_synopsis(), but rewritten to | |
18 handle triple quotes and to return the whole text instead of just | |
19 the synopsis''' | |
20 result = [] | |
21 | |
22 line = file.readline() | |
23 while line[:1] == '#' or not line.strip(): | |
24 line = file.readline() | |
25 if not line: | |
26 break | |
27 | |
28 start = line[:3] | |
29 if start == '"""' or start == "'''": | |
30 line = line[3:] | |
31 while line: | |
32 if line.rstrip().endswith(start): | |
33 line = line.split(start)[0] | |
34 if line: | |
35 result.append(line) | |
36 break | |
37 elif not line: | |
38 return None # unmatched delimiter | |
39 result.append(line) | |
40 line = file.readline() | |
41 else: | |
42 return None | |
43 | |
44 return ''.join(result) | |
45 | 12 |
46 def listexts(header, exts, indent=1): | 13 def listexts(header, exts, indent=1): |
47 '''return a text listing of the given extensions''' | 14 '''return a text listing of the given extensions''' |
48 if not exts: | 15 if not exts: |
49 return '' | 16 return '' |