-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
48 lines (40 loc) · 1.7 KB
/
main.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
import importlib
import types
import itasca
import stubgenc
importlib.reload(stubgenc)
class PackageGenerator(object):
def __init__(self, package):
self.package = package
self.all_packages = dict()
def find_package(self, name, module):
for sub_name, instance in vars(module).items():
if not isinstance(instance, types.ModuleType):
continue
if sub_name.startswith('_'):
continue
if hasattr(instance, '__package__') and instance.__package__:
continue
if instance in self.all_packages.values():
continue
total_name = f'{name}/{sub_name}'
if total_name == 'itasca/util':
continue
print(total_name)
self.all_packages[total_name] = instance
self.find_package(total_name, instance)
def generate(self):
self.all_packages['itasca'] = self.package
self.find_package('itasca', self.package)
for name, package in self.all_packages.items():
path = '{}/__init__.py'.format(name)
other_imports = [key.replace(name + '/', '')
for key in self.all_packages.keys()
if key.startswith(name + '/')]
other_imports = [other_import for other_import in other_imports if other_import]
other_imports = [other_import for other_import in other_imports if '/' not in other_import]
try:
stubgenc.generate_stub_for_c_module(package, path, other_import=other_imports)
except (AssertionError, TypeError):
print('Error', name)
PackageGenerator(itasca).generate()