When trying to run cloudbase-init using Python 3.12, it errors out
ModuleNotFoundError: No module named 'imp'.
The 'imp' module was replaced with similar functionality from module
importlib.
These two implementations are equivalent:
```python
import imp
import os
import site
wmi_path = None
for packages_path in site.getsitepackages():
path = os.path.join(packages_path, "wmi.py")
if os.path.isfile(path):
wmi_path = path
break
wmi_module_name = "wmi"
wmi_module = imp.load_source(wmi_module_name, wmi_path)
```
```python
import importlib.util
import os
import site
wmi_path = None
for packages_path in site.getsitepackages():
path = os.path.join(packages_path, "wmi.py")
if os.path.isfile(path):
wmi_path = path
break
wmi_module_name = "wmi"
wmi_module_spec = importlib.util.spec_from_file_location(wmi_module_name, wmi_path)
wmi_module = importlib.util.module_from_spec(wmi_module_spec)
wmi_module_spec.loader.exec_module(wmi_module)
```
Fixes: https://github.com/cloudbase/cloudbase-init/issues/139
Change-Id: I6490c6d9922efea26ab8d167a0d6e41ce34d6c2c
Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1.4 KiB
1.4 KiB