From 5abc11c4390d3e2364b89d038e306e22870e9fff Mon Sep 17 00:00:00 2001 From: zhoulinhui Date: Sun, 30 Aug 2020 22:08:45 +0800 Subject: [PATCH] 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: Iba4d686f9452728dd6c90a5c2e37e59dc78c6e2b --- tools/check_i18n.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/check_i18n.py b/tools/check_i18n.py index f07aed73b..9c49f941e 100644 --- a/tools/check_i18n.py +++ b/tools/check_i18n.py @@ -13,7 +13,7 @@ # under the License. import compiler -import imp +import importlib.util import os.path import sys @@ -112,11 +112,20 @@ def check_i18n(input_file, i18n_msg_predicates, msg_format_checkers, debug): return v.error +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 + + if __name__ == '__main__': input_path = sys.argv[1] cfg_path = sys.argv[2] try: - cfg_mod = imp.load_source('', cfg_path) + cfg_mod = load_module('', cfg_path) except Exception: print("Load cfg module failed", file=sys.stderr) sys.exit(1)