Skip to content

Commit b5d837a

Browse files
author
Michael Johansen
committed
Update nipanel to pull stubs from ni-apis-python packages
Signed-off-by: Michael Johansen <[email protected]>
1 parent 8920ee6 commit b5d837a

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

poetry.lock

Lines changed: 24 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ packages = [{ include = "nipanel", from = "src" }]
1010
python = ">=3.9,<4.0,!=3.9.7" # Exclude 3.9.7 due to streamlit not supporting it
1111
grpcio = {version=">=1.49.0,<2.0"}
1212
protobuf = {version=">=4.21"}
13-
ni-measurement-plugin-sdk = {version=">=2.3"}
13+
ni-measurement-plugin-sdk = {version=">=2.4.0dev1", allow-prereleases = true }
14+
# ni-measurement-plugin-sdk-service = {version=">=2.4.0dev1"}
15+
# ni-measurement-plugin-sdk-generator = {version=">=2.4.0dev1"}
1416
typing-extensions = ">=4.13.2"
1517
streamlit = ">=1.24"
1618
nitypes = {version=">=0.1.0dev8", allow-prereleases=true}
1719
numpy = ">=1.22"
1820
debugpy = ">=1.8.1"
21+
ni-protobuf-types = { version = ">=0.1.0dev2", allow-prereleases = true }
22+
ni-panels-v1-proto = { version = ">=0.1.0dev1", allow-prereleases = true }
1923

2024
[tool.poetry.group.dev.dependencies]
2125
types-grpcio = ">=1.0"

src/nipanel/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from importlib.metadata import version
44

5-
from ni.protobuf.types import array_pb2
65
from nipanel._panel_value_accessor import PanelValueAccessor
76
from nipanel._streamlit_panel import StreamlitPanel
87
from nipanel._streamlit_panel_initializer import (

src/nipanel/converters/protobuf_types.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import nitypes.bintime as bt
99
import numpy as np
10-
from ni.protobuf.types import attribute_value_pb2, scalar_pb2, array_pb2
11-
from ni.protobuf.types.precision_timestamp_pb2 import PrecisionTimestamp
12-
from ni.protobuf.types.scalar_conversion import scalar_from_protobuf, scalar_to_protobuf
10+
from ni.protobuf.types import scalar_pb2, array_pb2
1311
from ni.protobuf.types.precision_timestamp_conversion import (
1412
bintime_datetime_from_protobuf,
1513
bintime_datetime_to_protobuf,
1614
)
15+
from ni.protobuf.types.precision_timestamp_pb2 import PrecisionTimestamp
16+
from ni.protobuf.types.scalar_conversion import scalar_from_protobuf, scalar_to_protobuf
1717
from ni.protobuf.types.waveform_conversion import (
1818
float64_analog_waveform_from_protobuf,
1919
float64_analog_waveform_to_protobuf,
@@ -63,15 +63,11 @@ def protobuf_message(self) -> Type[array_pb2.BytesArray]:
6363
"""The type-specific protobuf message for the Python type."""
6464
return array_pb2.BytesArray
6565

66-
def to_protobuf_message(
67-
self, python_value: Collection[bytes]
68-
) -> array_pb2.BytesArray:
66+
def to_protobuf_message(self, python_value: Collection[bytes]) -> array_pb2.BytesArray:
6967
"""Convert the collection of byte strings to array_pb2.BytesArray."""
7068
return self.protobuf_message(values=python_value)
7169

72-
def to_python_value(
73-
self, protobuf_message: array_pb2.BytesArray
74-
) -> Collection[bytes]:
70+
def to_python_value(self, protobuf_message: array_pb2.BytesArray) -> Collection[bytes]:
7571
"""Convert the protobuf message to a Python collection of byte strings."""
7672
return list(protobuf_message.values)
7773

@@ -89,15 +85,11 @@ def protobuf_message(self) -> Type[array_pb2.DoubleArray]:
8985
"""The type-specific protobuf message for the Python type."""
9086
return array_pb2.DoubleArray
9187

92-
def to_protobuf_message(
93-
self, python_value: Collection[float]
94-
) -> array_pb2.DoubleArray:
88+
def to_protobuf_message(self, python_value: Collection[float]) -> array_pb2.DoubleArray:
9589
"""Convert the collection of floats to array_pb2.DoubleArray."""
9690
return self.protobuf_message(values=python_value)
9791

98-
def to_python_value(
99-
self, protobuf_message: array_pb2.DoubleArray
100-
) -> Collection[float]:
92+
def to_python_value(self, protobuf_message: array_pb2.DoubleArray) -> Collection[float]:
10193
"""Convert the protobuf message to a Python collection of floats."""
10294
return list(protobuf_message.values)
10395

@@ -137,20 +129,15 @@ def protobuf_message(self) -> Type[array_pb2.StringArray]:
137129
"""The type-specific protobuf message for the Python type."""
138130
return array_pb2.StringArray
139131

140-
def to_protobuf_message(
141-
self, python_value: Collection[str]
142-
) -> array_pb2.StringArray:
132+
def to_protobuf_message(self, python_value: Collection[str]) -> array_pb2.StringArray:
143133
"""Convert the collection of strings to panel_types_pb2.StringCollection."""
144134
return self.protobuf_message(values=python_value)
145135

146-
def to_python_value(
147-
self, protobuf_message: array_pb2.StringArray
148-
) -> Collection[str]:
136+
def to_python_value(self, protobuf_message: array_pb2.StringArray) -> Collection[str]:
149137
"""Convert the protobuf message to a Python collection of strings."""
150138
return list(protobuf_message.values)
151139

152140

153-
154141
class Double2DArrayConverter(CollectionConverter2D[float, array_pb2.Double2DArray]):
155142
"""A converter between Collection[Collection[float]] and Double2DArray."""
156143

@@ -164,8 +151,10 @@ def protobuf_message(self) -> Type[array_pb2.Double2DArray]:
164151
"""The type-specific protobuf message for the Python type."""
165152
return array_pb2.Double2DArray
166153

167-
def to_protobuf_message(self, python_value: Collection[Collection[float]]) -> array_pb2.Double2DArray:
168-
"""Convert the Python Collection[Collection[float]] to a protobuf array_pb2.Double2DArray."""
154+
def to_protobuf_message(
155+
self, python_value: Collection[Collection[float]]
156+
) -> array_pb2.Double2DArray:
157+
"""Convert the Python Collection[Collection[float]] to a protobuf Double2DArray."""
169158
rows = len(python_value)
170159
if rows:
171160
visitor = iter(python_value)
@@ -180,8 +169,10 @@ def to_protobuf_message(self, python_value: Collection[Collection[float]]) -> ar
180169
flat_list = [item for subcollection in python_value for item in subcollection]
181170
return array_pb2.Double2DArray(rows=rows, columns=columns, data=flat_list)
182171

183-
def to_python_value(self, protobuf_message: array_pb2.Double2DArray) -> Collection[Collection[float]]:
184-
"""Convert the protobuf array_pb2.Double2DArray to a Python Collection[Collection[float]]."""
172+
def to_python_value(
173+
self, protobuf_message: array_pb2.Double2DArray
174+
) -> Collection[Collection[float]]:
175+
"""Convert the protobuf Double2DArray to a Python Collection[Collection[float]]."""
185176
if not protobuf_message.data:
186177
return []
187178
if len(protobuf_message.data) % protobuf_message.columns != 0:

tests/unit/test_protobuf_type_conversion.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import datetime as dt
2-
from typing_extensions import Mapping
2+
33

44
import numpy
55
import pytest
6-
from ni.protobuf.types import attribute_value_pb2, scalar_pb2, array_pb2
6+
from ni.protobuf.types import array_pb2, attribute_value_pb2, scalar_pb2
77
from ni.protobuf.types.waveform_pb2 import (
88
DoubleAnalogWaveform,
99
WaveformAttributeValue,
1010
)
1111
from nitypes.bintime import DateTime
1212
from nitypes.scalar import Scalar
1313
from nitypes.waveform import AnalogWaveform, NoneScaleMode, SampleIntervalMode, Timing
14+
from typing_extensions import Mapping
1415

1516
from nipanel.converters.protobuf_types import (
1617
Double2DArrayConverter,
@@ -298,7 +299,7 @@ def test___scalar_protobuf_value_unset___convert___throws_type_error() -> None:
298299
with pytest.raises(ValueError) as exc:
299300
_ = converter.to_python_value(protobuf_value)
300301

301-
assert exc.value.args[0].startswith("Unexpected value for protobuf_value.WhichOneOf")
302+
assert exc.value.args[0].startswith("Could not determine the data type of 'value'.")
302303

303304

304305
def test___scalar_protobuf_units_unset___convert___python_units_blank() -> None:

0 commit comments

Comments
 (0)