diff --git a/gajim/gui/__init__.py b/gajim/gui/__init__.py index 680f53cf2b0f9d5f664d8b2a2180a4be72921931..f4d05f8ef822840f18ad2d67c18d19a996034a9b 100644 --- a/gajim/gui/__init__.py +++ b/gajim/gui/__init__.py @@ -13,26 +13,41 @@ def __init__(self, name, fallback=None): if fallback is not None: self._fallback_path = Path(__file__).parent.parent / fallback - self._suffix = 'pyc' if sys.platform == 'win32' else 'py' - def find_spec(self, fullname, _path, _target=None): if not fullname.startswith('gajim.gui'): return None _namespace, module_name = fullname.rsplit('.', 1) - module_path = self._path / f'{module_name}.{self._suffix}' - - if not module_path.exists(): - if self._fallback_path is None: - return None - - module_path = self._fallback_path / f'{module_name}.{self._suffix}' - if not module_path.exists(): - return None + module_path = self._find_module(module_name) + if module_path is None: + return None spec = importlib.util.spec_from_file_location(fullname, module_path) return spec + def _find_module(self, module_name): + module_path = self._path / f'{module_name}.py' + if module_path.exists(): + return module_path + + module_path = self._path / f'{module_name}.pyc' + if module_path.exists(): + return module_path + + if self._fallback_path is None: + return None + + module_path = self._fallback_path / f'{module_name}.py' + if module_path.exists(): + return module_path + + module_path = self._fallback_path / f'{module_name}.pyc' + if module_path.exists(): + return module_path + + return None + + def init(name, fallback=None): sys.meta_path.append(GUIFinder(name, fallback=fallback))