Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
solidiquis committed Jun 15, 2024
1 parent 6c22bc4 commit f6b312d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 46 deletions.
11 changes: 3 additions & 8 deletions python/lib/sift_py/ingestion/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ def as_pb(self, klass: Type[ProtobufMessage]) -> Optional[ProtobufMessage]:
unit=self.unit or "",
description=self.description or "",
data_type=self.data_type.value,
enum_types=[
try_cast_pb(etype, ChannelEnumTypePb) for etype in self.enum_types
],
enum_types=[try_cast_pb(etype, ChannelEnumTypePb) for etype in self.enum_types],
bit_field_elements=[
try_cast_pb(el, ChannelBitFieldElementPb)
for el in self.bit_field_elements
try_cast_pb(el, ChannelBitFieldElementPb) for el in self.bit_field_elements
],
)

Expand Down Expand Up @@ -191,9 +188,7 @@ def empty_value() -> IngestWithConfigDataChannelValue:
return IngestWithConfigDataChannelValue(empty=Empty())


def is_data_type(
val: IngestWithConfigDataChannelValue, target_type: ChannelDataType
) -> bool:
def is_data_type(val: IngestWithConfigDataChannelValue, target_type: ChannelDataType) -> bool:
if target_type == ChannelDataType.DOUBLE:
return val.HasField("double")
elif target_type == ChannelDataType.STRING:
Expand Down
28 changes: 7 additions & 21 deletions python/lib/sift_py/ingestion/config/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def _try_from_yaml_str(yaml_str: str) -> TelemetryConfig:

asset_name = any_as(config.get("asset_name"), str)
if asset_name is None or len(asset_name) == 0:
raise YamlConfigError(
"Expected a non-blank string for top-level 'asset_name' property"
)
raise YamlConfigError("Expected a non-blank string for top-level 'asset_name' property")

ingestion_client_key = any_as(config.get("ingestion_client_key"), str)
if ingestion_client_key is None or len(ingestion_client_key) == 0:
Expand Down Expand Up @@ -86,30 +84,22 @@ def _deserialize_channels_from_yaml(
for raw_channel_config in raw_channel_configs:
channel_name = any_as(raw_channel_config.get("name"), str)
if channel_name is None or len(channel_name) == 0:
raise YamlConfigError(
"Expected channel to have a non-blank 'name' property"
)
raise YamlConfigError("Expected channel to have a non-blank 'name' property")

channel_data_type_str = any_as(raw_channel_config.get("data_type"), str)
if channel_data_type_str is None or len(channel_data_type_str) == 0:
raise YamlConfigError(
"Missing property for 'flows.channel.data_type' property"
)
raise YamlConfigError("Missing property for 'flows.channel.data_type' property")

channel_data_type = ChannelDataType.from_str(channel_data_type_str)
if channel_data_type is None:
raise YamlConfigError(
"Invalid property for 'flows.channel.data_type' property"
)
raise YamlConfigError("Invalid property for 'flows.channel.data_type' property")

description = any_as(raw_channel_config.get("description"), str)
unit = any_as(raw_channel_config.get("unit"), str)
component = any_as(raw_channel_config.get("component"), str)

bit_field_elements = []
raw_bit_field_elements = any_as(
raw_channel_config.get("bit_field_elements"), list
)
raw_bit_field_elements = any_as(raw_channel_config.get("bit_field_elements"), list)
if raw_bit_field_elements is not None:
for element in raw_bit_field_elements:
el = _deserialize_bit_field_element_from_yaml(element)
Expand Down Expand Up @@ -168,15 +158,11 @@ def _deserialize_bit_field_element_from_yaml(
def _deserialize_enum_type_from_yaml(enum_type: Any) -> ChannelEnumType:
name = any_as(enum_type.get("name"), str)
if name is None or len(name) == 0:
raise YamlConfigError(
"Expected a non-blank value for 'flows.channels.enum_types.name'"
)
raise YamlConfigError("Expected a non-blank value for 'flows.channels.enum_types.name'")

key = any_as(enum_type.get("key"), int)
if key is None:
raise YamlConfigError(
"Expected an integer value for 'flows.channels.enum_types.key'"
)
raise YamlConfigError("Expected an integer value for 'flows.channels.enum_types.key'")

return ChannelEnumType(
name=name,
Expand Down
4 changes: 1 addition & 3 deletions python/lib/sift_py/ingestion/config/yaml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def test_telemetry_config():
assert log_channel.description == "asset logs"
assert log_channel.data_type == ChannelDataType.STRING

velocity_channel, voltage_channel, vehicle_state_channel, gpio_channel = (
readings_flow.channels
)
velocity_channel, voltage_channel, vehicle_state_channel, gpio_channel = readings_flow.channels
assert velocity_channel.name == "velocity"
assert velocity_channel.data_type == ChannelDataType.DOUBLE
assert velocity_channel.unit == "Miles Per Hour"
Expand Down
7 changes: 2 additions & 5 deletions python/lib/sift_py/ingestion/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ def __init__(self, name: str, channels: List[ChannelConfig]):
self.name = name
self.channels = channels
self.channel_by_fqn = {
self.__class__.compute_fqn(c.name, c.component): i
for i, c in enumerate(channels)
self.__class__.compute_fqn(c.name, c.component): i for i, c in enumerate(channels)
}

def get_channel(
self, name: str, component: Optional[str] = ""
) -> Optional[ChannelConfig]:
def get_channel(self, name: str, component: Optional[str] = "") -> Optional[ChannelConfig]:
"""
Retrieves a `ChannelConfig` by its fully qualified name. Returns `None` if it cannot be found.
"""
Expand Down
8 changes: 2 additions & 6 deletions python/lib/sift_py/ingestion/impl/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def __init__(
run_id: Optional[str] = None,
end_stream_on_error: bool = False,
):
self.ingestion_config = self.__class__.__get_or_create_ingestion_config(
channel, config
)
self.ingestion_config = self.__class__.__get_or_create_ingestion_config(channel, config)
self.asset_name = config.asset_name
self.transport_channel = channel
self.run_id = run_id
Expand Down Expand Up @@ -159,9 +157,7 @@ def create_ingestion_request(
@staticmethod
def __get_or_create_ingestion_config(channel: SiftChannel, config: TelemetryConfig):
# TODO: Handle case where new Flows are added to an existing ingestion config
ingestion_config = get_ingestion_config_by_client_key(
channel, config.ingestion_client_key
)
ingestion_config = get_ingestion_config_by_client_key(channel, config.ingestion_client_key)

if ingestion_config is not None:
return ingestion_config
Expand Down
4 changes: 1 addition & 3 deletions python/lib/sift_py/ingestion/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def try_create_ingestion_request(
validations on your own, prefer to use `create_ingestion_request`. Any errors that occur during
ingestion will be handled by the Sift API.
"""
return super().try_create_ingestion_request(
flow_name, timestamp, channel_values
)
return super().try_create_ingestion_request(flow_name, timestamp, channel_values)

def create_ingestion_request(
self,
Expand Down

0 comments on commit f6b312d

Please sign in to comment.