@@ -860,35 +860,41 @@ def find_module(self, id: str) -> Optional[str]:
860
860
return None
861
861
862
862
def find_modules_recursive (self , module : str ) -> List [BuildSource ]:
863
+ hits = set () # type: Set[str]
864
+ result = [] # type: List[BuildSource]
865
+ for src in self ._find_modules_recursive (module ):
866
+ if src .module not in hits :
867
+ hits .add (src .module )
868
+ result .append (src )
869
+ return result
870
+
871
+ def _find_modules_recursive (self , module : str ) -> List [BuildSource ]:
863
872
module_paths = self ._find_module (module )
864
873
865
- result = []
866
- hits = set () # type: Set[str]
874
+ srcs = [] # type: List[BuildSource]
867
875
for path in module_paths :
868
876
if is_module_path (path ) or is_pkg_path (path ):
869
- if module not in hits :
870
- result .append (BuildSource (path , module , None ))
871
- hits .add (module )
877
+ srcs .append (BuildSource (path , module , None ))
872
878
873
879
if is_pkg_path (path ):
874
880
path = dirname (path )
875
- result += self ._traverse_package (module , path )
881
+ for submodule in self ._find_submodules (module , path ):
882
+ srcs += self ._find_modules_recursive (submodule )
876
883
elif is_namespace_path (path ):
877
- result += self ._traverse_package (module , path )
884
+ for submodule in self ._find_submodules (module , path ):
885
+ srcs += self ._find_modules_recursive (submodule )
878
886
879
- return result
887
+ return srcs
880
888
881
- def _traverse_package (self , module , path ) -> List [BuildSource ]:
882
- result = [] # type: List[BuildSource]
889
+ def _find_submodules (self , module , path ) -> Iterator [str ]:
883
890
for item in list_dir (path ):
884
891
if item == '__init__.py' or item == '__init__.pyi' :
885
892
continue
886
893
887
894
if item .endswith (tuple (PYTHON_EXTENSIONS )):
888
895
item = item .split ('.' )[0 ]
889
896
890
- result += self .find_modules_recursive (module + '.' + item )
891
- return result
897
+ yield module + '.' + item
892
898
893
899
def _collect_paths (self , paths : List [str ], last_comp : str ) -> List [str ]:
894
900
"""
0 commit comments