File: check_api.py

package info (click to toggle)
statsmodels 0.13.5%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 46,912 kB
  • sloc: python: 240,079; f90: 612; sh: 467; javascript: 337; asm: 156; makefile: 131; ansic: 16; xml: 9
file content (54 lines) | stat: -rw-r--r-- 1,318 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
53
54
"""
Recursively find all .api entry points and compares the list of available
functions to what is contained in __all__
"""

import importlib
import pkgutil
from types import ModuleType

import statsmodels

api_modules = []

# Do not check paths with .{blacklist item}. in them
BLACKLIST = ["tests", "sandbox", "libqsturng"]


def import_submodules(module: ModuleType):
    """Import all submodules of a module, recursively."""
    for loader, module_name, is_pkg in pkgutil.walk_packages(
        module.__path__, module.__name__ + "."
    ):
        blacklisted = any([f".{bl}." in module_name for bl in BLACKLIST])
        if blacklisted:
            continue
        mod = importlib.import_module(module_name)
        if mod.__name__.endswith(".api"):
            api_modules.append(mod)


import_submodules(statsmodels)

missing = {}
for mod in api_modules:
    d = [v for v in dir(mod) if not v.startswith("_")]
    if "__all__" not in dir(mod):
        missing[mod.__name__] = d
        continue
    a = mod.__all__
    indiv = sorted(set(d).difference(a))
    if indiv:
        missing[mod.__name__] = indiv


for key in missing:
    print("-" * 60)
    print(key)
    print("-" * 60)
    print()
    for val in missing[key]:
        print(f'"{val}",')

if not missing:
    print("All api files are correct!")