@@ -99,9 +99,6 @@ def __init__(self, paths: Optional[Union[str, List[str]]], module: Optional[str]
99
99
self .text = text
100
100
self .type = type
101
101
102
- def __repr__ (self ) -> str :
103
- return 'BuildSource(%s)' % self .module
104
-
105
102
@property
106
103
def path (self ) -> Optional [str ]:
107
104
if self .paths :
@@ -771,7 +768,7 @@ def is_pkg(p: str) -> bool:
771
768
# of os.stat() calls is quickly more expensive than caching the
772
769
# os.listdir() outcome, and the advantage of the latter is that it
773
770
# gives us the case-correct filename on Windows and Mac.
774
- find_module_listdir_cache = {} # type: Dict[str, Optional[List[ str] ]]
771
+ find_module_listdir_cache = {} # type: Dict[str, Set[ str]]
775
772
776
773
# Cache for is_file()
777
774
find_module_is_file_cache = {} # type: Dict[str, bool]
@@ -787,7 +784,7 @@ def find_module_clear_caches() -> None:
787
784
find_module_isdir_cache .clear ()
788
785
789
786
790
- def list_dir (path : str ) -> Optional [ List [ str ] ]:
787
+ def list_dir (path : str ) -> Set [ str ]:
791
788
"""Return a cached directory listing.
792
789
793
790
Returns None if the path doesn't exist or isn't a directory.
@@ -797,7 +794,7 @@ def list_dir(path: str) -> Optional[List[str]]:
797
794
try :
798
795
res = os .listdir (path )
799
796
except OSError :
800
- res = None
797
+ res = set ()
801
798
find_module_listdir_cache [path ] = res
802
799
return res
803
800
@@ -816,7 +813,7 @@ def is_file(path: str) -> bool:
816
813
res = False
817
814
else :
818
815
names = list_dir (head )
819
- res = names is not None and tail in names and os .path .isfile (path )
816
+ res = tail in names and os .path .isfile (path )
820
817
find_module_is_file_cache [path ] = res
821
818
return res
822
819
@@ -879,12 +876,12 @@ def __init__(self,
879
876
880
877
self .lib_path = [os .path .normpath (p ) for p in lib_path ] # type: List[str]
881
878
self .namespaces_allowed = namespaces_allowed
882
- self ._find_module_cache = {} # type: Dict[str, Optional[BuildSource]]
879
+ self .find_module_cache = {} # type: Dict[str, Optional[BuildSource]]
883
880
884
881
def find_module (self , id : str ) -> Optional [BuildSource ]:
885
- if id not in self ._find_module_cache :
886
- self ._find_module_cache [id ] = self ._find_module (id )
887
- return self ._find_module_cache [id ]
882
+ if id not in self .find_module_cache :
883
+ self .find_module_cache [id ] = self ._find_module (id )
884
+ return self .find_module_cache [id ]
888
885
889
886
def find_modules_recursive (self , module : str ) -> List [BuildSource ]:
890
887
"""
@@ -923,7 +920,7 @@ def _find_modules_recursive(self, module: str) -> List[BuildSource]:
923
920
return srcs
924
921
925
922
def _find_submodules (self , module : str , path : str ) -> Iterator [str ]:
926
- for item in list_dir (path ) or [] :
923
+ for item in list_dir (path ):
927
924
if item .startswith (('__' , '.' )):
928
925
continue
929
926
@@ -2072,7 +2069,7 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
2072
2069
stubs_found = sum (g .path is not None and g .path .endswith ('.pyi' )
2073
2070
for g in graph .values ()),
2074
2071
graph_load_time = (t1 - t0 ),
2075
- fm_cache_size = len (find_module_cache ),
2072
+ fm_cache_size = len (manager . module_discovery . find_module_cache ),
2076
2073
fm_dir_cache_size = len (find_module_dir_cache ),
2077
2074
fm_listdir_cache_size = len (find_module_listdir_cache ),
2078
2075
fm_is_file_cache_size = len (find_module_is_file_cache ),
0 commit comments