blob: d7a9e5d552d1bdb8089c81e2c01a0731fb2ffe58 [file] [log] [blame]
Fred Drakeea4d2c02001-11-29 04:30:46 +00001#! /usr/bin/env python
2
3"""\
4This script prints out a list of undocumented symbols found in
Thomas Heller3e774232001-11-09 16:50:35 +00005Python include files, prefixed by their tag kind.
6
Thomas Heller64cdb482001-11-12 12:52:01 +00007Pass Python's include files to ctags, parse the output into a
8dictionary mapping symbol names to tag kinds.
Thomas Heller3e774232001-11-09 16:50:35 +00009
10Then, the .tex files from Python docs are read into a giant string.
11
12Finally all symbols not found in the docs are written to standard
13output, prefixed with their tag kind.
14"""
15
16# Which kind of tags do we need?
Fred Drakeea4d2c02001-11-29 04:30:46 +000017TAG_KINDS = "dpst"
Thomas Heller3e774232001-11-09 16:50:35 +000018
19# Doc sections to use
Thomas Heller64cdb482001-11-12 12:52:01 +000020DOCSECTIONS = ["api"]# ["api", "ext"]
Thomas Heller3e774232001-11-09 16:50:35 +000021
Thomas Heller64cdb482001-11-12 12:52:01 +000022# Only print symbols starting with this prefix,
Thomas Heller3e774232001-11-09 16:50:35 +000023# to get all symbols, use an empty string
Fred Drakeea4d2c02001-11-29 04:30:46 +000024PREFIXES = ("Py", "PY")
Thomas Heller3e774232001-11-09 16:50:35 +000025
Thomas Heller64cdb482001-11-12 12:52:01 +000026INCLUDEPATTERN = "*.h"
27
Thomas Heller3e774232001-11-09 16:50:35 +000028# end of customization section
29
30
31# Tested with EXUBERANT CTAGS
32# see http://ctags.sourceforge.net
33#
34# ctags fields are separated by tabs.
35# The first field is the name, the last field the type:
36# d macro definitions (and #undef names)
37# e enumerators
38# f function definitions
39# g enumeration names
40# m class, struct, or union members
41# n namespaces
42# p function prototypes and declarations
43# s structure names
44# t typedefs
45# u union names
46# v variable definitions
47# x extern and forward variable declarations
48
49import os, glob, re, sys, tempfile
50
Fred Drakeea4d2c02001-11-29 04:30:46 +000051def findnames(file, prefixes=()):
Thomas Heller3e774232001-11-09 16:50:35 +000052 names = {}
Fred Drakeea4d2c02001-11-29 04:30:46 +000053 for line in file.xreadlines():
Thomas Heller3e774232001-11-09 16:50:35 +000054 if line[0] == '!':
55 continue
56 fields = line.split()
57 name, tag = fields[0], fields[-1]
58 if tag == 'd' and name.endswith('_H'):
59 continue
Fred Drakeea4d2c02001-11-29 04:30:46 +000060 if prefixes:
61 sw = name.startswith
62 for prefix in prefixes:
63 if sw(prefix):
64 names[name] = tag
65 else:
Thomas Heller3e774232001-11-09 16:50:35 +000066 names[name] = tag
67 return names
68
Thomas Heller64cdb482001-11-12 12:52:01 +000069def print_undoc_symbols(prefix, docdir, incdir):
Thomas Heller3e774232001-11-09 16:50:35 +000070 docs = []
71
72 for sect in DOCSECTIONS:
Thomas Heller64cdb482001-11-12 12:52:01 +000073 for file in glob.glob(os.path.join(docdir, sect, "*.tex")):
Thomas Heller3e774232001-11-09 16:50:35 +000074 docs.append(open(file).read())
75
76 docs = "\n".join(docs)
77
Thomas Heller64cdb482001-11-12 12:52:01 +000078 incfiles = os.path.join(incdir, INCLUDEPATTERN)
79
Fred Drakeea4d2c02001-11-29 04:30:46 +000080 fp = os.popen("ctags -IDL_IMPORT --c-types=%s -f - %s"
81 % (TAG_KINDS, incfiles))
Thomas Heller3e774232001-11-09 16:50:35 +000082 dict = findnames(fp, prefix)
83 names = dict.keys()
84 names.sort()
85 for name in names:
86 if docs.find(name) == -1:
87 print dict[name], name
Thomas Heller3e774232001-11-09 16:50:35 +000088
89if __name__ == '__main__':
Thomas Heller64cdb482001-11-12 12:52:01 +000090 srcdir = os.path.dirname(sys.argv[0])
91 incdir = os.path.normpath(os.path.join(srcdir, "../../Include"))
92 docdir = os.path.normpath(os.path.join(srcdir, ".."))
Thomas Heller3e774232001-11-09 16:50:35 +000093
Fred Drakeea4d2c02001-11-29 04:30:46 +000094 print_undoc_symbols(PREFIXES, docdir, incdir)