Mercurial > cpython-lru_cache-weakref
annotate Doc/tools/custlib.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 85c87b3ac96b |
| children | 282927f7bde2 |
| rev | line source |
|---|---|
| 5691 | 1 # Generate custlib.tex, which is a site-specific library document. |
| 2 | |
| 3 # Phase I: list all the things that can be imported | |
| 4 | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
5 import glob |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
6 import os.path |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
7 import sys |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
8 |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
9 modules = {} |
| 5691 | 10 |
| 11 for modname in sys.builtin_module_names: | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
12 modules[modname] = modname |
| 5691 | 13 |
| 14 for dir in sys.path: | |
| 15 # Look for *.py files | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
16 filelist = glob.glob(os.path.join(dir, '*.py')) |
| 5691 | 17 for file in filelist: |
| 15088 | 18 path, file = os.path.split(file) |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
19 base, ext = os.path.splitext(file) |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
20 modules[base.lower()] = base |
| 5691 | 21 |
| 22 # Look for shared library files | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
23 filelist = (glob.glob(os.path.join(dir, '*.so')) + |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
24 glob.glob(os.path.join(dir, '*.sl')) + |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
25 glob.glob(os.path.join(dir, '*.o')) ) |
| 5691 | 26 for file in filelist: |
| 15088 | 27 path, file = os.path.split(file) |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
28 base, ext = os.path.splitext(file) |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
29 if base[-6:] == 'module': |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
30 base = base[:-6] |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
31 modules[base.lower()] = base |
| 5691 | 32 |
| 33 # Minor oddity: the types module is documented in libtypes2.tex | |
| 34 if modules.has_key('types'): | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
35 del modules['types'] |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
36 modules['types2'] = None |
| 5691 | 37 |
| 38 # Phase II: find all documentation files (lib*.tex) | |
| 39 # and eliminate modules that don't have one. | |
| 40 | |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
41 docs = {} |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
42 filelist = glob.glob('lib*.tex') |
| 5691 | 43 for file in filelist: |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
44 modname = file[3:-4] |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
45 docs[modname] = modname |
| 5691 | 46 |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
47 mlist = modules.keys() |
|
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
48 mlist = filter(lambda x, docs=docs: docs.has_key(x), mlist) |
| 5691 | 49 mlist.sort() |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
50 mlist = map(lambda x, docs=docs: docs[x], mlist) |
| 5691 | 51 |
|
25798
85c87b3ac96b
Use string methods; minor code cleanup.
Fred Drake <fdrake@acm.org>
parents:
15088
diff
changeset
|
52 modules = mlist |
| 5691 | 53 |
| 54 # Phase III: write custlib.tex | |
| 55 | |
| 56 # Write the boilerplate | |
| 57 # XXX should be fancied up. | |
| 58 print """\documentstyle[twoside,11pt,myformat]{report} | |
| 59 \\title{Python Library Reference} | |
| 60 \\input{boilerplate} | |
| 15088 | 61 \\makeindex % tell \\index to actually write the .idx file |
| 5691 | 62 \\begin{document} |
| 63 \\pagenumbering{roman} | |
| 64 \\maketitle | |
| 65 \\input{copyright} | |
| 66 \\begin{abstract} | |
| 67 \\noindent This is a customized version of the Python Library Reference. | |
| 68 \\end{abstract} | |
| 69 \\pagebreak | |
| 70 {\\parskip = 0mm \\tableofcontents} | |
| 71 \\pagebreak\\pagenumbering{arabic}""" | |
| 72 | |
| 73 for modname in mlist: | |
| 74 print "\\input{lib%s}" % (modname,) | |
| 75 | |
| 76 # Write the end | |
| 15088 | 77 print """\\input{custlib.ind} % Index |
| 5691 | 78 \\end{document}""" |
