Use importlib.util to replace imp
Since the imp module is deprecated and scheduled for removal in
Python 3.12 in favor of importlib, update the relevant libraries to
resolve any ModuleNotFoundError issues with Python 3.12.
Changes:
- use import importlib.util instead of import imp
Tested:
- Ran basic test pass with Python 3.10 and 3.12.
Change-Id: I25dde939dd25268b2ae329b0121858bec20ed03c
Signed-off-by: Brian Ma <chma0@nuvoton.com>
diff --git a/lib/state.py b/lib/state.py
index 00fa124..e48e8d8 100755
--- a/lib/state.py
+++ b/lib/state.py
@@ -27,7 +27,7 @@
compared with the expected state.
"""
-import imp
+import importlib.util
import os
import re
import sys
@@ -45,7 +45,9 @@
gru.my_import_resource("rest_client.robot")
base_path = (
- os.path.dirname(os.path.dirname(imp.find_module("gen_robot_print")[1]))
+ os.path.dirname(
+ os.path.dirname(importlib.util.find_spec("gen_robot_print").origin)
+ )
+ os.sep
)
sys.path.append(base_path + "data/")