1# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16import importlib.util
17import os
18import sys
19from importlib.abc import Loader
20from typing import Any
21
22
23def _load_source(name, path):  # type: (str, str) -> Any
24    spec = importlib.util.spec_from_file_location(name, path)
25    module = importlib.util.module_from_spec(spec)
26    sys.modules[spec.name] = module
27    assert isinstance(spec.loader, Loader)
28    spec.loader.exec_module(module)
29    return module
30
31
32idf_path = os.environ['IDF_PATH']
33
34# protocomm component related python files generated from .proto files
35constants_pb2 = _load_source('constants_pb2', idf_path + '/components/protocomm/python/constants_pb2.py')
36sec0_pb2      = _load_source('sec0_pb2',      idf_path + '/components/protocomm/python/sec0_pb2.py')
37sec1_pb2      = _load_source('sec1_pb2',      idf_path + '/components/protocomm/python/sec1_pb2.py')
38session_pb2   = _load_source('session_pb2',   idf_path + '/components/protocomm/python/session_pb2.py')
39
40# wifi_provisioning component related python files generated from .proto files
41wifi_constants_pb2 = _load_source('wifi_constants_pb2', idf_path + '/components/wifi_provisioning/python/wifi_constants_pb2.py')
42wifi_config_pb2    = _load_source('wifi_config_pb2',    idf_path + '/components/wifi_provisioning/python/wifi_config_pb2.py')
43wifi_scan_pb2      = _load_source('wifi_scan_pb2',      idf_path + '/components/wifi_provisioning/python/wifi_scan_pb2.py')
44
45# custom_provisioning component related python files generated from .proto files
46custom_config_pb2  = _load_source('custom_config_pb2',  idf_path +
47                                  '/examples/provisioning/legacy/custom_config/components/custom_provisioning/python/custom_config_pb2.py')
48