Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 1 | """This script prints out a list of undocumented symbols found in |
| 2 | Python include files, prefixed by their tag kind. |
| 3 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 4 | Pass Python's include files to ctags, parse the output into a |
| 5 | dictionary mapping symbol names to tag kinds. |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 6 | |
| 7 | Then, the .tex files from Python docs are read into a giant string. |
| 8 | |
| 9 | Finally all symbols not found in the docs are written to standard |
| 10 | output, prefixed with their tag kind. |
| 11 | """ |
| 12 | |
| 13 | # Which kind of tags do we need? |
| 14 | TAG_KINDS = "dpt" |
| 15 | |
| 16 | # Doc sections to use |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 17 | DOCSECTIONS = ["api"]# ["api", "ext"] |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 18 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 19 | # Only print symbols starting with this prefix, |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 20 | # to get all symbols, use an empty string |
| 21 | PREFIX = "Py" |
| 22 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 23 | INCLUDEPATTERN = "*.h" |
| 24 | |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 25 | # end of customization section |
| 26 | |
| 27 | |
| 28 | # Tested with EXUBERANT CTAGS |
| 29 | # see http://ctags.sourceforge.net |
| 30 | # |
| 31 | # ctags fields are separated by tabs. |
| 32 | # The first field is the name, the last field the type: |
| 33 | # d macro definitions (and #undef names) |
| 34 | # e enumerators |
| 35 | # f function definitions |
| 36 | # g enumeration names |
| 37 | # m class, struct, or union members |
| 38 | # n namespaces |
| 39 | # p function prototypes and declarations |
| 40 | # s structure names |
| 41 | # t typedefs |
| 42 | # u union names |
| 43 | # v variable definitions |
| 44 | # x extern and forward variable declarations |
| 45 | |
| 46 | import os, glob, re, sys, tempfile |
| 47 | |
| 48 | def findnames(file, prefix=""): |
| 49 | names = {} |
| 50 | for line in file.readlines(): |
| 51 | if line[0] == '!': |
| 52 | continue |
| 53 | fields = line.split() |
| 54 | name, tag = fields[0], fields[-1] |
| 55 | if tag == 'd' and name.endswith('_H'): |
| 56 | continue |
| 57 | if name.startswith(prefix): |
| 58 | names[name] = tag |
| 59 | return names |
| 60 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 61 | def print_undoc_symbols(prefix, docdir, incdir): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 62 | docs = [] |
| 63 | |
| 64 | for sect in DOCSECTIONS: |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 65 | for file in glob.glob(os.path.join(docdir, sect, "*.tex")): |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 66 | docs.append(open(file).read()) |
| 67 | |
| 68 | docs = "\n".join(docs) |
| 69 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 70 | incfiles = os.path.join(incdir, INCLUDEPATTERN) |
| 71 | |
| 72 | fp = os.popen("ctags -IDL_IMPORT --c-types=%s -f - %s" % (TAG_KINDS, incfiles)) |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 73 | dict = findnames(fp, prefix) |
| 74 | names = dict.keys() |
| 75 | names.sort() |
| 76 | for name in names: |
| 77 | if docs.find(name) == -1: |
| 78 | print dict[name], name |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 79 | |
| 80 | if __name__ == '__main__': |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 81 | srcdir = os.path.dirname(sys.argv[0]) |
| 82 | incdir = os.path.normpath(os.path.join(srcdir, "../../Include")) |
| 83 | docdir = os.path.normpath(os.path.join(srcdir, "..")) |
Thomas Heller | 3e77423 | 2001-11-09 16:50:35 +0000 | [diff] [blame] | 84 | |
Thomas Heller | 64cdb48 | 2001-11-12 12:52:01 +0000 | [diff] [blame] | 85 | print_undoc_symbols(PREFIX, docdir, incdir) |