esp_prov.py: Replaced deprecated function for loading modules

This commit is contained in:
Laukik Hase 2022-01-28 15:46:27 +05:30
parent e0968e506c
commit 954844a308

View File

@ -13,17 +13,20 @@
# limitations under the License.
#
import importlib.util
import os
import sys
from importlib.abc import Loader
from typing import Any
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)
def _load_source(name, path): # type: (str, str) -> Any
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
assert isinstance(spec.loader, Loader)
spec.loader.exec_module(module)
return module
idf_path = os.environ['IDF_PATH']