-
Notifications
You must be signed in to change notification settings - Fork 405
/
override_check.py
49 lines (36 loc) · 1.17 KB
/
override_check.py
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
#!/usr/lib/env python
#
# Module Documentation Override Check
#
# Verifies that any modules present in the _templates/overrides directory have all of their
# their exported functions included in the doc file.
from __future__ import print_function
import glob
import importlib
import os
import sys
modules_to_skip = ['metpy.xarray']
failed = False
for full_path in glob.glob('_templates/overrides/metpy.*.rst'):
filename = os.path.basename(full_path)
module = filename.split('.rst')[0]
if module in modules_to_skip:
continue
# Get all functions in the module
i = importlib.import_module(module)
functions = set(i.__all__)
# Get all lines in the file
with open(full_path) as f:
lines = f.read().splitlines()
lines = {line.strip() for line in lines}
# Check for any missing functions
missing_functions = functions - lines
if missing_functions:
failed = True
print('ERROR - The following functions are missing from the override file ' +
filename + ': ' + ', '.join(missing_functions), file=sys.stderr)
# Report status
if failed:
sys.exit(1)
else:
print('Override check successful.')