3 # Released to the public domain by Skip Montanaro, 28 March 2002
6 findsyms.py - try to identify undocumented symbols exported by modules
8 Usage: findsyms.py librefdir
10 For each lib*.tex file in the libref manual source directory, identify which
11 module is documented, import the module if possible, then search the LaTeX
12 source for the symbols global to that module. Report any that don't seem to
15 Certain exceptions are made to the list of undocumented symbols:
17 * don't mention symbols in which all letters are upper case on the
18 assumption they are manifest constants
20 * don't mention symbols that are themselves modules
22 * don't mention symbols that match those exported by os, math, string,
23 types, or __builtin__ modules
25 Finally, if a name is exported by the module but fails a getattr() lookup,
26 that anomaly is reported.
41 print >> sys
.stderr
, """
43 where 'dir' is the Library Reference Manual source directory.
44 """ % os
.path
.basename(sys
.argv
[0])
48 opts
, args
= getopt
.getopt(sys
.argv
[1:], "")
59 warnings
.filterwarnings("error")
61 pat
= re
.compile(r
"\\declaremodule\s*{[^}]*}\s*{([^}]*)}")
64 filelist
= glob
.glob(os
.path
.join(libdir
, "lib*.tex"))
70 mods
= re
.findall(pat
, data
)
72 print "No module declarations found in", f
75 # skip special modules
76 if modname
.startswith("__"):
79 mod
= __import__(modname
)
81 missing
.append(modname
)
83 except DeprecationWarning:
84 print "Deprecated module:", modname
86 if hasattr(mod
, "__all__"):
89 all
= [k
for k
in dir(mod
) if k
[0] != "_"]
93 if data
.find(name
) == -1:
94 # certain names are predominantly used for testing
95 if name
in ("main","test","_test"):
97 # is it some sort of manifest constant?
98 if name
.upper() == name
:
101 item
= getattr(mod
, name
)
102 except AttributeError:
103 print " ", name
, "exposed, but not an attribute"
105 # don't care about modules that might be exposed
106 if type(item
) == types
.ModuleType
:
108 # check a few modules which tend to be import *'d
110 for m
in (os
, math
, string
, __builtin__
, types
):
111 if hasattr(m
, name
) and item
== getattr(m
, name
):
114 if isglobal
: continue
116 print "Not mentioned in", modname
, "docs:"
121 print "Could not import:"
122 print " ", ", ".join(missing
)
124 if __name__
== "__main__":
127 except KeyboardInterrupt: