Skip to content

Commit 758eb74

Browse files
committed
Replace deprecated imp usage with importlib
Signed-off-by: Cole Robinson <[email protected]>
1 parent 79da19a commit 758eb74

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

setup.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
sys.exit(1)
1111

1212
import glob
13+
import importlib.util
1314
import os
1415
from pathlib import Path
1516
import shutil
@@ -33,18 +34,14 @@ def _import_buildconfig():
3334
# A bit of crazyness to import the buildconfig file without importing
3435
# the rest of virtinst, so the build process doesn't require all the
3536
# runtime deps to be installed
36-
import warnings
37-
38-
# 'imp' is deprecated. We use it elsewhere though too. Deal with using
39-
# the modern replacement when we replace all usage
40-
with warnings.catch_warnings():
41-
warnings.filterwarnings("ignore", category=DeprecationWarning)
42-
import imp
43-
buildconfig = imp.load_source('buildconfig', 'virtinst/buildconfig.py')
44-
if "libvirt" in sys.modules:
45-
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
46-
"not import virtinst.")
47-
return buildconfig.BuildConfig
37+
spec = importlib.util.spec_from_file_location(
38+
'buildconfig', 'virtinst/buildconfig.py')
39+
buildconfig = importlib.util.module_from_spec(spec)
40+
spec.loader.exec_module(buildconfig)
41+
if "libvirt" in sys.modules:
42+
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
43+
"not import virtinst.")
44+
return buildconfig.BuildConfig
4845

4946

5047
BuildConfig = _import_buildconfig()

tests/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This work is licensed under the GNU GPLv2 or later.
44
# See the COPYING file in the top-level directory.
55

6-
import imp
6+
import importlib
77
import os
88

99
# Need to do this before any tests or virtinst import
@@ -18,8 +18,9 @@
1818
# pylint: disable=wrong-import-position
1919
from virtinst import buildconfig
2020
from virtinst import log, reset_logging
21+
2122
# This sets all the cli bits back to their defaults
22-
imp.reload(buildconfig)
23+
importlib.reload(buildconfig)
2324

2425
from tests import utils
2526

0 commit comments

Comments
 (0)