File: check-API-refs.py

package info (click to toggle)
patsy 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,448 kB
  • sloc: python: 9,536; javascript: 204; makefile: 110
file content (52 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python

# NB: this currently works on both Py2 and Py3, and should be kept that way.

import sys
import re
from os.path import dirname, abspath

root = dirname(dirname(abspath(__file__)))
patsy_ref = root + "/doc/API-reference.rst"

doc_re = re.compile(r"^\.\. (.*):: ([^\(]*)")


def _documented(rst_path):
    documented = set()
    with open(rst_path) as rst_file:
        for line in rst_file:
            match = doc_re.match(line.rstrip())
            if match:
                directive = match.group(1)
                symbol = match.group(2)
                if directive not in ["module", "ipython"]:
                    documented.add(symbol)
        return documented


try:
    import patsy
except ImportError:
    sys.path.append(root)
    import patsy

documented = set(_documented(patsy_ref))
# print(documented)
exported = set(patsy.__all__)
missed = exported.difference(documented)
extra = documented.difference(exported)
if missed:
    print("DOCS MISSING FROM %s:" % (patsy_ref,))
    for m in sorted(missed):
        print("  %s" % (m,))
if extra:
    print("EXTRA DOCS IN %s:" % (patsy_ref,))
    for m in sorted(extra):
        print("  %s" % (m,))

if missed or extra:
    sys.exit(1)
else:
    print("Reference docs look good.")
    sys.exit(0)