From a8b6f6bb34864a6821174edbf7802b689e440db3 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Wed, 23 Aug 2023 17:13:23 +0200 Subject: [PATCH] Fix startup on Python 3.12 --- a/quodlibet/_import.py +++ b/quodlibet/_import.py @@ -8,6 +8,7 @@ import sys import importlib +import importlib.util class RedirectImportHook: @@ -31,6 +32,11 @@ def __init__(self, name, packages): self._name = name self._packages = packages + def find_spec(self, fullname, path, target=None): + loader = self.find_module(fullname, path) + if loader is not None: + return importlib.util.spec_from_loader(fullname, loader) + def find_module(self, fullname, path=None): package = fullname.split(".")[0] if package in self._packages: --- a/quodlibet/util/config.py +++ b/quodlibet/util/config.py @@ -377,7 +377,7 @@ def read(self, filename): with open(filename, "rb") as fileobj: fileobj = StringIO( fileobj.read().decode("utf-8", "surrogateescape")) - self._config.readfp(fileobj, filename) + self._config.read_file(fileobj, filename) except (IOError, OSError): return --- a/quodlibet/util/importhelper.py +++ b/quodlibet/util/importhelper.py @@ -92,8 +92,8 @@ def load_module(name, package, path): except KeyError: pass - loader = importlib.find_loader(fullname, [path]) - if loader is None: + spec = importlib.machinery.PathFinder.find_spec(fullname, [path]) + if spec is None: return # modules need a parent package @@ -101,7 +101,7 @@ def load_module(name, package, path): spec = importlib.machinery.ModuleSpec(package, None, is_package=True) sys.modules[package] = importlib.util.module_from_spec(spec) - mod = loader.load_module(fullname) + mod = spec.loader.load_module(fullname) # make it accessible from the parent, like __import__ does vars(sys.modules[package])[name] = mod