summaryrefslogtreecommitdiff
path: root/cinderclient
diff options
context:
space:
mode:
authorzhoulinhui <df.some@foxmail.com>2020-08-30 22:05:41 +0800
committerzhoulinhui <df.some@foxmail.com>2020-09-02 15:59:36 +0000
commitaebb6011e67955d5e54b8596eb0a3301877b9345 (patch)
treefafd932a333bd4a41bbece15327936492bb617f6 /cinderclient
parent12a6dc2ea58b750bdf7b688d45bb1c6df38e3684 (diff)
downloadpython-cinderclient-aebb6011e67955d5e54b8596eb0a3301877b9345.tar.gz
Use importlib to take place of imp module
The imp module is deprecated[1] since version 3.4, use importlib to instead [1]: https://docs.python.org/3/library/imp.html Change-Id: Ie250592bc183e8db1758b6cfa4681a45f4c489ab
Diffstat (limited to 'cinderclient')
-rw-r--r--cinderclient/client.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py
index b013c1e..24af7de 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -18,7 +18,7 @@
import glob
import hashlib
-import imp
+import importlib.util
import itertools
import logging
import os
@@ -791,6 +791,15 @@ def _discover_via_python_path():
yield name, module
+def load_module(name, path):
+ module_spec = importlib.util.spec_from_file_location(
+ name, path
+ )
+ module = importlib.util.module_from_spec(module_spec)
+ module_spec.loader.exec_module(module)
+ return module
+
+
def _discover_via_contrib_path(version):
module_path = os.path.dirname(os.path.abspath(__file__))
version_str = "v%s" % version.replace('.', '_')
@@ -803,7 +812,7 @@ def _discover_via_contrib_path(version):
if name == "__init__":
continue
- module = imp.load_source(name, ext_path)
+ module = load_module(name, ext_path)
yield name, module