-
Notifications
You must be signed in to change notification settings - Fork 5
/
package_analysis.py
90 lines (73 loc) · 2.49 KB
/
package_analysis.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import annotations
import argparse
import importlib
import inspect
white_list: list[str] = [
"kornia.augmentation",
"kornia.augmentation.auto",
"kornia.augmentation.container",
"kornia.color",
"kornia.contrib",
"kornia.enhance",
"kornia.feature",
"kornia.filters",
"kornia.geometry",
"kornia.geometry.calibration",
"kornia.geometry.camera",
"kornia.geometry.epipolar",
"kornia.geometry.liegroup",
"kornia.geometry.subpix",
"kornia.geometry.transform",
"kornia.io",
"kornia.losses",
"kornia.metrics",
"kornia.morphology",
"kornia.nerf",
"kornia.tracking",
"kornia.utils",
"kornia.x",
]
def get_public_operators(module) -> list[str]:
"""List all public operators in a module.
Args:
module (module): The module to list operators from.
Returns:
list[str]: A list of public operators.
"""
operators: list[str] = []
public_names: list[str] = getattr(module, '__all__', [])
if not public_names:
public_names = [name for name, _ in inspect.getmembers(module)]
name: str
for name in public_names:
if not name.startswith('_'):
obj = getattr(module, name, None)
if obj and (inspect.isfunction(obj) or inspect.isclass(obj)):
operators.append(name)
return operators
def list_package_operators() -> dict[str, list[str]]:
"""List all public operators in a package."""
operators_per_module: dict[str, list[str]] = {}
for module_name in white_list:
try:
module = importlib.import_module(module_name)
operators: list[str] = get_public_operators(module)
operators_per_module[module_name] = operators
module_hierarchy: str = module_name.replace('.', ' -> ')
except ImportError as e:
print(f'Failed to import {module_name}: {e}')
return operators_per_module
if __name__ == '__main__':
# get all public operators in a package
operators_per_module: dict[str, list[str]] = \
list_package_operators()
# count the number of operators
num_operators: int = 0
# print the result
for module_name, operators in operators_per_module.items():
module_hierarchy: str = module_name.replace('.', ' -> ')
print(f'{module_hierarchy}')
for operator in operators:
print(f' {operator}')
num_operators += 1
print(f'## Number of operators: {num_operators}')