Update the code for imp's removal with python 3.12 (#865)
* Changed the `__init__.py` file to use importlib instead of imp.
This commit is contained in:
parent
fd96fc6d2e
commit
5cbb06292d
@ -6,7 +6,8 @@ from i3pystatus.core.settings import SettingsBase
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user