https://bugs.gentoo.org/929423 https://github.com/libratbag/libratbag/pull/1569 https://github.com/libratbag/libratbag/commit/27b0d4a2d9cd21fa9f11a0770d94c578db6324d1 --- a/tools/toolbox.py +++ b/tools/toolbox.py @@ -21,7 +21,8 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -import imp +import importlib.util +import importlib.machinery import os import subprocess import sys @@ -45,8 +46,11 @@ def import_non_standard_path(name, path): # If any of the following calls raises an exception, # there's a problem we can't handle -- let the caller handle it. - with open(path, 'rb') as fp: - module = imp.load_module(name, fp, os.path.basename(path), ('.py', 'rb', imp.PY_SOURCE)) + loader = importlib.machinery.SourceFileLoader(name, path) + spec = importlib.util.spec_from_file_location(name, path, loader=loader) + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + loader.exec_module(module) return module @@ -107,7 +111,7 @@ def sync_dbus(): main_context.iteration(False) -ratbagctl = import_non_standard_path(RATBAGCTL_NAME, RATBAGCTL_PATH) +import_non_standard_path(RATBAGCTL_NAME, RATBAGCTL_PATH) from ratbagctl import open_ratbagd, get_parser, RatbagError, RatbagErrorCapability # NOQA