Skip to content

Commit 47332ac

Browse files
committed
feat(api): Replace imp with importlib
1 parent f24cb55 commit 47332ac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cmdb-api/api/lib/cmdb/value.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from __future__ import unicode_literals
55

6-
import imp
6+
import importlib.util
77

88
import copy
99
import jinja2
@@ -198,11 +198,11 @@ def _compute_attr_value_from_script(script, ci_dict):
198198

199199
try:
200200
path = script_f.name
201-
dir_name, name = os.path.dirname(path), os.path.basename(path)[:-3]
201+
name = os.path.basename(path)[:-3]
202202

203-
fp, path, desc = imp.find_module(name, [dir_name])
204-
205-
mod = imp.load_module(name, fp, path, desc)
203+
spec = importlib.util.spec_from_file_location(name, path)
204+
mod = importlib.util.module_from_spec(spec)
205+
spec.loader.exec_module(mod)
206206

207207
if hasattr(mod, 'computed'):
208208
return mod.computed()

0 commit comments

Comments
 (0)