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. # limitations under the License.
# #
import importlib.util
import os import os
import sys
from importlib.abc import Loader
from typing import Any
def _load_source(name, path): def _load_source(name, path): # type: (str, str) -> Any
try: spec = importlib.util.spec_from_file_location(name, path)
from importlib.machinery import SourceFileLoader module = importlib.util.module_from_spec(spec)
return SourceFileLoader(name, path).load_module() sys.modules[spec.name] = module
except ImportError: assert isinstance(spec.loader, Loader)
# importlib.machinery doesn't exists in Python 2 so we will use imp (deprecated in Python 3) spec.loader.exec_module(module)
import imp return module
return imp.load_source(name, path)
idf_path = os.environ['IDF_PATH'] idf_path = os.environ['IDF_PATH']