Skip to content

Commit

Permalink
Fix imports which depend on modified sys path
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Dec 20, 2022
1 parent 0128a74 commit 0c2d19d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
22 changes: 12 additions & 10 deletions examples/common/pigweed/rpc_console/py/chip_rpc/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,8 @@
from typing import Any, BinaryIO, Callable, Collection

import pw_cli.log
# Protos
from attributes_service import attributes_service_pb2
from button_service import button_service_pb2
from chip_rpc.plugins.device_toolbar import DeviceToolbar
from chip_rpc.plugins.helper_scripts import HelperScripts
from descriptor_service import descriptor_service_pb2
from device_service import device_service_pb2
from echo_service import echo_pb2
from lighting_service import lighting_service_pb2
from locking_service import locking_service_pb2
from ot_cli_service import ot_cli_service_pb2
from pw_console import PwConsoleEmbed
from pw_console.__main__ import create_temp_log_file
from pw_console.pyserial_wrapper import SerialWithLogging
Expand All @@ -67,7 +58,18 @@
from pw_rpc.console_tools.console import ClientInfo, flattened_rpc_completions
from pw_tokenizer import tokens
from pw_tokenizer.database import LoadTokenDatabases
from pw_tokenizer.detokenize import Detokenizer, detokenize_base64
from pw_tokenizer.detokenize import Detokenizer

# Protos
# isort: off
from attributes_service import attributes_service_pb2
from button_service import button_service_pb2
from descriptor_service import descriptor_service_pb2
from device_service import device_service_pb2
from echo_service import echo_pb2
from lighting_service import lighting_service_pb2
from locking_service import locking_service_pb2
from ot_cli_service import ot_cli_service_pb2
from thread_service import thread_service_pb2
from wifi_service import wifi_service_pb2

Expand Down
11 changes: 6 additions & 5 deletions scripts/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import logging
import sys

import click
from idl.generators import FileSystemGeneratorStorage, GeneratorStorage
from idl.generators.registry import GENERATORS, CodeGenerator

try:
import coloredlogs
_has_coloredlogs = True
except:
except ImportError:
_has_coloredlogs = False

try:
from idl.matter_idl_parser import CreateParser
except:
except ImportError:
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from idl.matter_idl_parser import CreateParser

# isort: off
from idl.generators import FileSystemGeneratorStorage, GeneratorStorage
from idl.generators.registry import GENERATORS, CodeGenerator


class ListGeneratedFilesStorage(GeneratorStorage):
"""
Expand Down
15 changes: 8 additions & 7 deletions scripts/idl/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import unittest
from dataclasses import dataclass, field
from typing import List

import yaml
from idl.generators import GeneratorStorage
from idl.generators.bridge import BridgeGenerator
from idl.generators.cpp.application import CppApplicationGenerator
from idl.generators.java import JavaGenerator
from idl.matter_idl_types import Idl

try:
from idl.matter_idl_parser import CreateParser
except:
except ImportError:
import sys

sys.path.append(os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')))
from idl.matter_idl_parser import CreateParser

# isort: off
from idl.generators import GeneratorStorage
from idl.generators.bridge import BridgeGenerator
from idl.generators.cpp.application import CppApplicationGenerator
from idl.generators.java import JavaGenerator
from idl.matter_idl_types import Idl


TESTS_DIR = os.path.join(os.path.dirname(__file__), "tests")
REGENERATE_GOLDEN_IMAGES = False
Expand Down
11 changes: 3 additions & 8 deletions scripts/idl/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import logging
import os
import xml.sax
import xml.sax.handler

from idl.zapxml import ParseSource, ParseXmls

try:
from idl.matter_idl_types import Idl
except:
from idl.zapxml import ParseSource, ParseXmls
except ImportError:
import sys

sys.path.append(os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')))
from idl.matter_idl_types import Idl
from idl.zapxml import ParseSource, ParseXmls


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions scripts/idl_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import logging
import os
import sys
from typing import List, Optional

import click
import coloredlogs
import idl.lint

try:
from idl import matter_idl_parser
except:
except ImportError:
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from idl import matter_idl_parser

# isort: off
import idl.lint


# Supported log levels, mapping string values required for argument
# parsing into logging constants
Expand Down
8 changes: 4 additions & 4 deletions src/test_driver/efr32/py/nl_test_runner/nl_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from typing import Any

import serial # type: ignore
# RPC Protos
from nl_test_service import nl_test_pb2
from pw_hdlc.rpc import HdlcRpcClient, default_channels, write_to_file
from pw_status import Status

# RPC Protos
from nl_test_service import nl_test_pb2 # isort:skip

PW_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -103,7 +103,7 @@ def on_error_callback(call_object, error):
colors.HEADER + streamed_data.test_suite_start.suite_name) + colors.ENDC)
if streamed_data.HasField("test_case_run"):
print("\t{}: {}".format(streamed_data.test_case_run.test_case_name,
FAIL_STRING if streamed_data.test_case_run.failed else PASS_STRING))
FAIL_STRING if streamed_data.test_case_run.failed else PASS_STRING))
if streamed_data.HasField("test_suite_tests_run_summary"):
total_run += streamed_data.test_suite_tests_run_summary.total_count
total_failed += streamed_data.test_suite_tests_run_summary.failed_count
Expand Down

0 comments on commit 0c2d19d

Please sign in to comment.