4 This script prints out a list of undocumented symbols found in
5 Python include files, prefixed by their tag kind.
7 Pass Python's include files to ctags, parse the output into a
8 dictionary mapping symbol names to tag kinds.
10 Then, the .tex files from Python docs are read into a giant string.
12 Finally all symbols not found in the docs are written to standard
13 output, prefixed with their tag kind.
16 # Which kind of tags do we need?
20 DOCSECTIONS
= ["api"]# ["api", "ext"]
22 # Only print symbols starting with this prefix,
23 # to get all symbols, use an empty string
24 PREFIXES
= ("Py", "PY")
26 INCLUDEPATTERN
= "*.h"
28 # end of customization section
31 # Tested with EXUBERANT CTAGS
32 # see http://ctags.sourceforge.net
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)
38 # f function definitions
40 # m class, struct, or union members
42 # p function prototypes and declarations
46 # v variable definitions
47 # x extern and forward variable declarations
49 import os
, glob
, re
, sys
51 def findnames(file, prefixes
=()):
53 for line
in file.xreadlines():
57 name
, tag
= fields
[0], fields
[-1]
58 if tag
== 'd' and name
.endswith('_H'):
62 for prefix
in prefixes
:
69 def print_undoc_symbols(prefix
, docdir
, incdir
):
72 for sect
in DOCSECTIONS
:
73 for file in glob
.glob(os
.path
.join(docdir
, sect
, "*.tex")):
74 docs
.append(open(file).read())
76 docs
= "\n".join(docs
)
78 incfiles
= os
.path
.join(incdir
, INCLUDEPATTERN
)
80 fp
= os
.popen("ctags -IPyAPI_FUNC -IPy_GCC_ATTRIBUTE --c-types=%s -f - %s"
81 % (TAG_KINDS
, incfiles
))
82 dict = findnames(fp
, prefix
)
86 if not re
.search("%s\\W" % name
, docs
):
87 print dict[name
], name
89 if __name__
== '__main__':
90 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
, ".."))
94 print_undoc_symbols(PREFIXES
, docdir
, incdir
)