mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
examples, tools: Fix Python3 deprecation warning for the imp module
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import imp
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -41,7 +40,7 @@ import Utility
|
|||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
client = imp.load_source("client", expath + "/scripts/test.py")
|
client = Utility.load_source("client", expath + "/scripts/test.py")
|
||||||
|
|
||||||
|
|
||||||
# Due to connectivity issues (between runner host and DUT) in the runner environment,
|
# Due to connectivity issues (between runner host and DUT) in the runner environment,
|
||||||
|
@@ -19,7 +19,6 @@ from __future__ import print_function
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from builtins import str
|
from builtins import str
|
||||||
from builtins import range
|
from builtins import range
|
||||||
import imp
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -43,7 +42,7 @@ import Utility
|
|||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
client = imp.load_source("client", expath + "/scripts/adder.py")
|
client = Utility.load_source("client", expath + "/scripts/adder.py")
|
||||||
|
|
||||||
|
|
||||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||||
|
@@ -18,7 +18,6 @@ from __future__ import division
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from builtins import range
|
from builtins import range
|
||||||
import imp
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -44,7 +43,7 @@ import Utility
|
|||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
client = imp.load_source("client", expath + "/scripts/client.py")
|
client = Utility.load_source("client", expath + "/scripts/client.py")
|
||||||
|
|
||||||
|
|
||||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||||
|
@@ -13,21 +13,31 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import imp
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def _load_source(name, path):
|
||||||
|
try:
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
return SourceFileLoader(name, path).load_module()
|
||||||
|
except ImportError:
|
||||||
|
# importlib.machinery doesn't exists in Python 2 so we will use imp (deprecated in Python 3)
|
||||||
|
import imp
|
||||||
|
return imp.load_source(name, path)
|
||||||
|
|
||||||
|
|
||||||
idf_path = os.environ['IDF_PATH']
|
idf_path = os.environ['IDF_PATH']
|
||||||
|
|
||||||
# protocomm component related python files generated from .proto files
|
# protocomm component related python files generated from .proto files
|
||||||
constants_pb2 = imp.load_source("constants_pb2", idf_path + "/components/protocomm/python/constants_pb2.py")
|
constants_pb2 = _load_source("constants_pb2", idf_path + "/components/protocomm/python/constants_pb2.py")
|
||||||
sec0_pb2 = imp.load_source("sec0_pb2", idf_path + "/components/protocomm/python/sec0_pb2.py")
|
sec0_pb2 = _load_source("sec0_pb2", idf_path + "/components/protocomm/python/sec0_pb2.py")
|
||||||
sec1_pb2 = imp.load_source("sec1_pb2", idf_path + "/components/protocomm/python/sec1_pb2.py")
|
sec1_pb2 = _load_source("sec1_pb2", idf_path + "/components/protocomm/python/sec1_pb2.py")
|
||||||
session_pb2 = imp.load_source("session_pb2", idf_path + "/components/protocomm/python/session_pb2.py")
|
session_pb2 = _load_source("session_pb2", idf_path + "/components/protocomm/python/session_pb2.py")
|
||||||
|
|
||||||
# wifi_provisioning component related python files generated from .proto files
|
# wifi_provisioning component related python files generated from .proto files
|
||||||
wifi_constants_pb2 = imp.load_source("wifi_constants_pb2", idf_path + "/components/wifi_provisioning/python/wifi_constants_pb2.py")
|
wifi_constants_pb2 = _load_source("wifi_constants_pb2", idf_path + "/components/wifi_provisioning/python/wifi_constants_pb2.py")
|
||||||
wifi_config_pb2 = imp.load_source("wifi_config_pb2", idf_path + "/components/wifi_provisioning/python/wifi_config_pb2.py")
|
wifi_config_pb2 = _load_source("wifi_config_pb2", idf_path + "/components/wifi_provisioning/python/wifi_config_pb2.py")
|
||||||
|
|
||||||
# custom_provisioning component related python files generated from .proto files
|
# custom_provisioning component related python files generated from .proto files
|
||||||
custom_config_pb2 = imp.load_source("custom_config_pb2", idf_path +
|
custom_config_pb2 = _load_source("custom_config_pb2", idf_path +
|
||||||
"/examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py")
|
"/examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py")
|
||||||
|
@@ -43,13 +43,12 @@ Template Config File::
|
|||||||
- name: xxx
|
- name: xxx
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: add a function to use suitable import lib for python2 and python3
|
|
||||||
import imp
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import TestCase
|
import TestCase
|
||||||
|
|
||||||
|
from Utility import load_source
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_lower_case_bytes(item):
|
def _convert_to_lower_case_bytes(item):
|
||||||
"""
|
"""
|
||||||
@@ -169,8 +168,7 @@ class Parser(object):
|
|||||||
output = dict()
|
output = dict()
|
||||||
for key in overwrite:
|
for key in overwrite:
|
||||||
_path = overwrite[key]["path"]
|
_path = overwrite[key]["path"]
|
||||||
# TODO: add a function to use suitable import lib for python2 and python3
|
_module = load_source(str(hash(_path)), overwrite[key]["path"])
|
||||||
_module = imp.load_source(str(hash(_path)), overwrite[key]["path"])
|
|
||||||
output[key] = _module.__getattribute__(overwrite[key]["class"])
|
output[key] = _module.__getattribute__(overwrite[key]["class"])
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@@ -17,8 +17,7 @@ import os
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import types
|
import types
|
||||||
import copy
|
import copy
|
||||||
# TODO: add a function to use suitable import lib for python2 and python3
|
from Utility import load_source
|
||||||
import imp
|
|
||||||
|
|
||||||
|
|
||||||
class Search(object):
|
class Search(object):
|
||||||
@@ -31,8 +30,7 @@ class Search(object):
|
|||||||
print("Try to get cases from: " + file_name)
|
print("Try to get cases from: " + file_name)
|
||||||
test_functions = []
|
test_functions = []
|
||||||
try:
|
try:
|
||||||
# TODO: add a function to use suitable import lib for python2 and python3
|
mod = load_source(str(hash(file_name)), file_name)
|
||||||
mod = imp.load_source(str(hash(file_name)), file_name)
|
|
||||||
for func in [mod.__getattribute__(x) for x in dir(mod)
|
for func in [mod.__getattribute__(x) for x in dir(mod)
|
||||||
if isinstance(mod.__getattribute__(x), types.FunctionType)]:
|
if isinstance(mod.__getattribute__(x), types.FunctionType)]:
|
||||||
try:
|
try:
|
||||||
|
@@ -36,3 +36,13 @@ def console_log(data, color="white", end="\n"):
|
|||||||
# reset color to white for later logs
|
# reset color to white for later logs
|
||||||
print(_COLOR_CODES["white"] + u"\r")
|
print(_COLOR_CODES["white"] + u"\r")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def load_source(name, path):
|
||||||
|
try:
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
return SourceFileLoader(name, path).load_module()
|
||||||
|
except ImportError:
|
||||||
|
# importlib.machinery doesn't exists in Python 2 so we will use imp (deprecated in Python 3)
|
||||||
|
import imp
|
||||||
|
return imp.load_source(name, path)
|
||||||
|
Reference in New Issue
Block a user