return None when the module actually doesn't exist

This commit is contained in:
sneakers-the-rat 2023-10-04 22:08:01 -07:00
parent 5438b2489b
commit d46e86c676

View file

@ -801,12 +801,16 @@ class EctopicModelFinder(MetaPathFinder):
# get submodule beneath model stem # get submodule beneath model stem
submod = fullname.replace(self.MODEL_STEM, '').lstrip('.') submod = fullname.replace(self.MODEL_STEM, '').lstrip('.')
base_path = Path(self.path, *submod.split('.')) base_path = Path(self.path, *submod.split('.'))
# switch if we're asked for a package or a module # switch if we're asked for a package or a module
mod_path = Path(str(base_path) + '.py') mod_path = Path(str(base_path) + '.py')
pkg_path = base_path / '__init__.py'
if mod_path.exists(): if mod_path.exists():
import_path = mod_path import_path = mod_path
elif pkg_path.exists():
import_path = pkg_path
else: else:
import_path = base_path / '__init__.py' return None
spec = importlib.util.spec_from_file_location(fullname, import_path) spec = importlib.util.spec_from_file_location(fullname, import_path)
return spec return spec