File tree 1 file changed +19
-6
lines changed 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 32
32
current_from_import_import ,
33
33
)
34
34
35
- import imp
36
35
import os
37
36
import sys
38
37
import warnings
@@ -143,6 +142,10 @@ def find_modules(path):
143
142
filenames = os .listdir (path )
144
143
except EnvironmentError :
145
144
filenames = []
145
+
146
+ if py3 :
147
+ finder = importlib .machinery .FileFinder (path )
148
+
146
149
for name in filenames :
147
150
if not any (name .endswith (suffix ) for suffix in SUFFIXES ):
148
151
# Possibly a package
@@ -163,12 +166,22 @@ def find_modules(path):
163
166
is_package = False
164
167
with warnings .catch_warnings ():
165
168
warnings .simplefilter ("ignore" , ImportWarning )
166
- fo , pathname , _ = imp .find_module (name , [path ])
167
- if fo is not None :
168
- fo .close ()
169
+ if py3 :
170
+ spec = finder .find_spec (name )
171
+ if spec is None :
172
+ continue
173
+ if spec .submodule_search_locations is not None :
174
+ pathname = spec .submodule_search_locations [0 ]
175
+ is_package = True
176
+ else :
177
+ pathname = spec .origin
169
178
else :
170
- # Yay, package
171
- is_package = True
179
+ fo , pathname , _ = imp .find_module (name , [path ])
180
+ if fo is not None :
181
+ fo .close ()
182
+ else :
183
+ # Yay, package
184
+ is_package = True
172
185
except (ImportError , IOError , SyntaxError ):
173
186
continue
174
187
except UnicodeEncodeError :
You can’t perform that action at this time.
0 commit comments