@@ -20,6 +20,23 @@ def __is_defined_in_submodule(submodule_name_prefix, x):
2020 return False
2121
2222
23+ def __get_submodule_symbols (submodule_full_name , submodule ):
24+
25+ from inspect import getmembers , ismodule
26+ all_ = []
27+
28+ for x_name , symbol in getmembers (submodule ):
29+ if not x_name .startswith ('_' ):
30+ if __is_defined_in_submodule (submodule_full_name , symbol ):
31+ # print('{} is exported'.format(x_name))
32+ if ismodule (symbol ):
33+ all_ = all_ + __get_submodule_symbols (submodule_full_name + '.' + x_name , symbol )
34+ else :
35+ all_ .append (x_name )
36+
37+ return all_
38+
39+
2340def __get_all_submodules_symbols (pkg_name , submodules_to_export ):
2441 """
2542 Generates the list of symbol names that can be used in the `__all__` variable in init.py
@@ -34,8 +51,8 @@ def __get_all_submodules_symbols(pkg_name, submodules_to_export):
3451 :param submodules_to_export: a list of submodule names to export
3552 :return:
3653 """
37- from inspect import getmembers
3854 from copy import copy
55+
3956 from importlib import import_module
4057
4158 # first create a copy of the submodules list
@@ -46,11 +63,8 @@ def __get_all_submodules_symbols(pkg_name, submodules_to_export):
4663 submodule_full_name = pkg_name + '.' + submodule
4764 imported_module = import_module (submodule_full_name )
4865 # print(imported_module.__name__)
49- for x_name , symbol in getmembers (imported_module ):
50- if not x_name .startswith ('_' ):
51- if __is_defined_in_submodule (submodule_full_name , symbol ):
52- # print('{} is exported'.format(x_name))
53- all_ .append (x_name )
66+ all_ = all_ + __get_submodule_symbols (submodule_full_name , imported_module )
67+
5468 return all_
5569
5670
0 commit comments