blob: 541984fa7fa1e2dc309fa141a4be5f2651228136 [file] [log] [blame]
Thomas Heller3e774232001-11-09 16:50:35 +00001"""This script prints out a list of undocumented symbols found in
2Python include files, prefixed by their tag kind.
3
Thomas Heller64cdb482001-11-12 12:52:01 +00004Pass Python's include files to ctags, parse the output into a
5dictionary mapping symbol names to tag kinds.
Thomas Heller3e774232001-11-09 16:50:35 +00006
7Then, the .tex files from Python docs are read into a giant string.
8
9Finally all symbols not found in the docs are written to standard
10output, prefixed with their tag kind.
11"""
12
13# Which kind of tags do we need?
14TAG_KINDS = "dpt"
15
16# Doc sections to use
Thomas Heller64cdb482001-11-12 12:52:01 +000017DOCSECTIONS = ["api"]# ["api", "ext"]
Thomas Heller3e774232001-11-09 16:50:35 +000018
Thomas Heller64cdb482001-11-12 12:52:01 +000019# Only print symbols starting with this prefix,
Thomas Heller3e774232001-11-09 16:50:35 +000020# to get all symbols, use an empty string
21PREFIX = "Py"
22
Thomas Heller64cdb482001-11-12 12:52:01 +000023INCLUDEPATTERN = "*.h"
24
Thomas Heller3e774232001-11-09 16:50:35 +000025# 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
46import os, glob, re, sys, tempfile
47
48def 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 Heller64cdb482001-11-12 12:52:01 +000061def print_undoc_symbols(prefix, docdir, incdir):
Thomas Heller3e774232001-11-09 16:50:35 +000062 docs = []
63
64 for sect in DOCSECTIONS:
Thomas Heller64cdb482001-11-12 12:52:01 +000065 for file in glob.glob(os.path.join(docdir, sect, "*.tex")):
Thomas Heller3e774232001-11-09 16:50:35 +000066 docs.append(open(file).read())
67
68 docs = "\n".join(docs)
69
Thomas Heller64cdb482001-11-12 12:52:01 +000070 incfiles = os.path.join(incdir, INCLUDEPATTERN)
71
72 fp = os.popen("ctags -IDL_IMPORT --c-types=%s -f - %s" % (TAG_KINDS, incfiles))
Thomas Heller3e774232001-11-09 16:50:35 +000073 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 Heller3e774232001-11-09 16:50:35 +000079
80if __name__ == '__main__':
Thomas Heller64cdb482001-11-12 12:52:01 +000081 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 Heller3e774232001-11-09 16:50:35 +000084
Thomas Heller64cdb482001-11-12 12:52:01 +000085 print_undoc_symbols(PREFIX, docdir, incdir)