Skip to content

Commit 2d11f4a

Browse files
committed
XSConsoleImported: switch from imp to importlib for python 3.12 support
This switches away from deprecated `imp`, and breaks support for python 2.7, but I expect this branch to really support only python3 now, so we likely don't care about adding backward compatibility here. Signed-off-by: Yann Dirson <yann.dirson@vates.tech>
1 parent 1f6b7aa commit 2d11f4a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

XSConsoleImporter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# with this program; if not, write to the Free Software Foundation, Inc.,
1616
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

18-
import imp, os, re, sys, traceback
18+
import importlib.util, os, re, sys, traceback
1919

2020
from XSConsoleLog import *
2121
from XSConsoleMenus import *
@@ -46,8 +46,10 @@ def ImportAbsDir(cls, inDir):
4646
try:
4747
try:
4848
# Import using variable as module name
49-
(fileObj, pathName, description) = imp.find_module(importName, [root])
50-
imp.load_module(importName, fileObj, pathName, description)
49+
spec = importlib.util.spec_from_file_location(
50+
importName, os.path.join(root, filename))
51+
module = importlib.util.module_from_spec(spec)
52+
spec.loader.exec_module(module)
5153
except Exception as e:
5254
try: XSLogError(*traceback.format_tb(sys.exc_info()[2]))
5355
except: pass

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
name = "XSConsole"
44
dynamic = ["version"]
55
description = "Xenserver Status Report"
6-
requires-python = ">=2.7, <3.12"
6+
requires-python = ">=3.6"
77
license = "GPL-2.0-or-later"
88
keywords = ["xenserver", "xen-project"]
99
authors = [
@@ -20,13 +20,13 @@ classifiers = [
2020
"Environment :: Console",
2121
"Development Status :: 5 - Production/Stable",
2222
"Operating System :: POSIX :: Linux :: XenServer/XCP-ng Dom0",
23-
"Programming Language :: Python :: 2.7",
2423
"Programming Language :: Python :: 3.6",
2524
"Programming Language :: Python :: 3.7",
2625
"Programming Language :: Python :: 3.8",
2726
"Programming Language :: Python :: 3.9",
2827
"Programming Language :: Python :: 3.10",
2928
"Programming Language :: Python :: 3.11",
29+
"Programming Language :: Python :: 3.12",
3030
"Programming Language :: Python :: Implementation :: CPython",
3131
"Topic :: System :: Logging",
3232
"Topic :: System :: Monitoring",

0 commit comments

Comments
 (0)