@@ -142,6 +142,29 @@ def find_module(
142
142
type = ModuleType .C_BUILTIN ,
143
143
)
144
144
145
+ if submodule_path is not None :
146
+ search_paths = list (submodule_path )
147
+ else :
148
+ search_paths = sys .path
149
+
150
+ suffixes = (".py" , ".pyi" , importlib .machinery .BYTECODE_SUFFIXES [0 ])
151
+ for entry in search_paths :
152
+ package_directory = os .path .join (entry , modname )
153
+ for suffix in suffixes :
154
+ package_file_name = "__init__" + suffix
155
+ file_path = os .path .join (package_directory , package_file_name )
156
+ if os .path .isfile (file_path ):
157
+ return ModuleSpec (
158
+ name = modname ,
159
+ location = package_directory ,
160
+ type = ModuleType .PKG_DIRECTORY ,
161
+ )
162
+ for suffix , type_ in ImportlibFinder ._SUFFIXES :
163
+ file_name = modname + suffix
164
+ file_path = os .path .join (entry , file_name )
165
+ if os .path .isfile (file_path ):
166
+ return ModuleSpec (name = modname , location = file_path , type = type_ )
167
+
145
168
# sys.stdlib_module_names was added in Python 3.10
146
169
if PY310_PLUS :
147
170
# If the module is a stdlib module, check whether this is a frozen module. Note that
@@ -194,28 +217,6 @@ def find_module(
194
217
except ValueError :
195
218
pass
196
219
197
- if submodule_path is not None :
198
- search_paths = list (submodule_path )
199
- else :
200
- search_paths = sys .path
201
-
202
- suffixes = (".py" , ".pyi" , importlib .machinery .BYTECODE_SUFFIXES [0 ])
203
- for entry in search_paths :
204
- package_directory = os .path .join (entry , modname )
205
- for suffix in suffixes :
206
- package_file_name = "__init__" + suffix
207
- file_path = os .path .join (package_directory , package_file_name )
208
- if os .path .isfile (file_path ):
209
- return ModuleSpec (
210
- name = modname ,
211
- location = package_directory ,
212
- type = ModuleType .PKG_DIRECTORY ,
213
- )
214
- for suffix , type_ in ImportlibFinder ._SUFFIXES :
215
- file_name = modname + suffix
216
- file_path = os .path .join (entry , file_name )
217
- if os .path .isfile (file_path ):
218
- return ModuleSpec (name = modname , location = file_path , type = type_ )
219
220
return None
220
221
221
222
def contribute_to_path (
0 commit comments