diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 9b9ce8de..3fae6852 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -6,7 +6,8 @@ from i3pystatus.core.util import formatp, get_module import argparse -import imp +import importlib.util +import importlib.machinery import logging import os @@ -35,6 +36,19 @@ def clock_example(): status.run() +def load_source(modname, filename): + """ + From: https://docs.python.org/3/whatsnew/3.12.html?highlight=load_source#imp + """ + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module + def main(): parser = argparse.ArgumentParser(description=''' run i3pystatus configuration file. Starts i3pystatus clock example if no arguments were provided @@ -44,6 +58,6 @@ def main(): if args.config: module_name = "i3pystatus-config" - imp.load_source(module_name, args.config) + load_source(module_name, args.config) else: clock_example()