Switch to oslo_utils.importutils to load module
The imp module is deprecated since a while and the load_source method has been removed from docs because broken [1][2]. Switch to oslo_utils.importutils for the same. [1] https://bugs.python.org/issue14551 [2] https://mail.python.org/pipermail/python-ideas/2014-December/030265.html Change-Id: Ic567e48b925befe2c196a5d46de8e504f273387e
This commit is contained in:
parent
452d2a29eb
commit
e254845470
@ -15,11 +15,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import imp
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_utils import importutils
|
||||||
import routes
|
import routes
|
||||||
import six
|
import six
|
||||||
import webob.dec
|
import webob.dec
|
||||||
@ -540,7 +540,8 @@ class ExtensionManager(object):
|
|||||||
mod_name, file_ext = os.path.splitext(os.path.split(f)[-1])
|
mod_name, file_ext = os.path.splitext(os.path.split(f)[-1])
|
||||||
ext_path = os.path.join(path, f)
|
ext_path = os.path.join(path, f)
|
||||||
if file_ext.lower() == '.py' and not mod_name.startswith('_'):
|
if file_ext.lower() == '.py' and not mod_name.startswith('_'):
|
||||||
mod = imp.load_source(mod_name, ext_path)
|
mod = importutils.import_module(
|
||||||
|
'tacker.extensions.' + mod_name)
|
||||||
ext_name = mod_name[0].upper() + mod_name[1:]
|
ext_name = mod_name[0].upper() + mod_name[1:]
|
||||||
new_ext_class = getattr(mod, ext_name, None)
|
new_ext_class = getattr(mod, ext_name, None)
|
||||||
if not new_ext_class:
|
if not new_ext_class:
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import compiler
|
import compiler
|
||||||
import imp
|
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from olso_utils import importutils
|
||||||
|
|
||||||
|
|
||||||
def is_localized(node):
|
def is_localized(node):
|
||||||
"""Check message wrapped by _()"""
|
"""Check message wrapped by _()"""
|
||||||
@ -116,9 +117,8 @@ def check_i18n(input_file, i18n_msg_predicates, msg_format_checkers, debug):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
input_path = sys.argv[1]
|
input_path = sys.argv[1]
|
||||||
cfg_path = sys.argv[2]
|
|
||||||
try:
|
try:
|
||||||
cfg_mod = imp.load_source('', cfg_path)
|
cfg_mod = importutils.import_module(tools.check_i18n)
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Load cfg module failed", file=sys.stderr)
|
print("Load cfg module failed", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -128,8 +128,8 @@ if __name__ == '__main__':
|
|||||||
black_list = cfg_mod.file_black_list
|
black_list = cfg_mod.file_black_list
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
if len(sys.argv) > 3:
|
if len(sys.argv) > 2:
|
||||||
if sys.argv[3] == '-d':
|
if sys.argv[2] == '-d':
|
||||||
debug = True
|
debug = True
|
||||||
|
|
||||||
if os.path.isfile(input_path):
|
if os.path.isfile(input_path):
|
||||||
|
2
tox.ini
2
tox.ini
@ -54,7 +54,7 @@ commands =
|
|||||||
whitelist_externals = bash
|
whitelist_externals = bash
|
||||||
|
|
||||||
[testenv:i18n]
|
[testenv:i18n]
|
||||||
commands = python ./tools/check_i18n.py ./tacker ./tools/i18n_cfg.py
|
commands = python ./tools/check_i18n.py ./tacker
|
||||||
|
|
||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
deps = -r{toxinidir}/doc/requirements.txt
|
deps = -r{toxinidir}/doc/requirements.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user