Replace deprecated `imp` usage with `importlib`
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
79da19ad07
commit
758eb74ba3
21
setup.py
21
setup.py
|
@ -10,6 +10,7 @@ if sys.version_info.major < 3:
|
|||
sys.exit(1)
|
||||
|
||||
import glob
|
||||
import importlib.util
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
@ -33,18 +34,14 @@ def _import_buildconfig():
|
|||
# A bit of crazyness to import the buildconfig file without importing
|
||||
# the rest of virtinst, so the build process doesn't require all the
|
||||
# runtime deps to be installed
|
||||
import warnings
|
||||
|
||||
# 'imp' is deprecated. We use it elsewhere though too. Deal with using
|
||||
# the modern replacement when we replace all usage
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
import imp
|
||||
buildconfig = imp.load_source('buildconfig', 'virtinst/buildconfig.py')
|
||||
if "libvirt" in sys.modules:
|
||||
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
|
||||
"not import virtinst.")
|
||||
return buildconfig.BuildConfig
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
'buildconfig', 'virtinst/buildconfig.py')
|
||||
buildconfig = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(buildconfig)
|
||||
if "libvirt" in sys.modules:
|
||||
raise RuntimeError("Found libvirt in sys.modules. setup.py should "
|
||||
"not import virtinst.")
|
||||
return buildconfig.BuildConfig
|
||||
|
||||
|
||||
BuildConfig = _import_buildconfig()
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import imp
|
||||
import importlib
|
||||
import os
|
||||
|
||||
# Need to do this before any tests or virtinst import
|
||||
|
@ -18,8 +18,9 @@ os.environ.pop("LANGUAGE", None)
|
|||
# pylint: disable=wrong-import-position
|
||||
from virtinst import buildconfig
|
||||
from virtinst import log, reset_logging
|
||||
|
||||
# This sets all the cli bits back to their defaults
|
||||
imp.reload(buildconfig)
|
||||
importlib.reload(buildconfig)
|
||||
|
||||
from tests import utils
|
||||
|
||||
|
|
Loading…
Reference in New Issue