Skip to content

Commit e455d45

Browse files
committed
Add a script to check that __all__ in __init__.py is correct
1 parent 611ef85 commit e455d45

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

python/allcheck.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import re
4+
import glob
5+
6+
import phonenumbers
7+
8+
INTERNAL_FILES = ['phonenumbers/util.py',
9+
'phonenumbers/re_util.py',
10+
'phonenumbers/unicode_util.py']
11+
CLASS_RE = re.compile(r"^class +([A-Za-z][_A-Za-z0-9]+)[ \(:]")
12+
FUNCTION_RE = re.compile("^def +([A-Za-z][_A-Za-z0-9]+)[ \(]")
13+
CONSTANT_RE = re.compile("^([A-Z][_A-Z0-9]+) *= *")
14+
15+
grepped_all = set()
16+
for filename in glob.glob('phonenumbers/*.py'):
17+
if filename in INTERNAL_FILES:
18+
continue
19+
with file(filename, "r") as infile:
20+
for line in infile:
21+
m = CLASS_RE.match(line)
22+
if m:
23+
grepped_all.add(m.group(1))
24+
m = FUNCTION_RE.match(line)
25+
if m:
26+
grepped_all.add(m.group(1))
27+
m = CONSTANT_RE.match(line)
28+
if m:
29+
grepped_all.add(m.group(1))
30+
31+
code_all = set(phonenumbers.__all__)
32+
code_not_grepped = (code_all - grepped_all)
33+
grepped_not_code = (grepped_all - code_all)
34+
if len(code_not_grepped) > 0:
35+
print >> sys.stderr, "Found the following in __all__ but not in grepped code:"
36+
for identifier in code_not_grepped:
37+
print >> sys.stderr, " %s" % identifier
38+
if len(grepped_not_code) > 0:
39+
print >> sys.stderr, "Found the following in grepped code but not in__all__:"
40+
for identifier in grepped_not_code:
41+
print >> sys.stderr, " %s" % identifier

0 commit comments

Comments
 (0)