Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e77423

Browse files
author
Thomas Heller
committed
Script to print undocumented symbols found in Python header files.
1 parent 52a17be commit 3e77423

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Doc/tools/undoc_symbols.py

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

0 commit comments

Comments
 (0)