Skip to content

Commit 5d5404f

Browse files
Mike ProsserMike Prosser
authored andcommitted
fix linter issues
1 parent 394b74a commit 5d5404f

File tree

6 files changed

+185
-26
lines changed

6 files changed

+185
-26
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ See [GitHub's official documentation](https://help.github.com/articles/using-pul
2222
# Getting Started
2323

2424
This is the command to generate the files in /src/ni/pythonpanel/v1/:
25-
`poetry run python -m grpc_tools.protoc --proto_path=protos --python_out=src/ --grpc_python_out=src/ --plugin=protoc-gen-mypy=.venv\Scripts\protoc-gen-mypy.exe --mypy_out=src/ ni/pythonpanel/v1/python_panel_service.proto`
25+
`poetry run python -m grpc_tools.protoc --proto_path=protos --python_out=src/ --grpc_python_out=src/ --plugin=protoc-gen-mypy=.venv\Scripts\protoc-gen-mypy.exe --mypy_out=src/ --mypy_grpc_out=src/ ni/pythonpanel/v1/python_panel_service.proto`
2626

2727
# Testing
2828

poetry.lock

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

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ grpcio = {version=">=1.49.0,<2.0"}
1212
protobuf = {version=">=4.21"}
1313
ni-measurement-plugin-sdk = {version=">=2.3"}
1414

15+
[tool.poetry.group.dev.dependencies]
16+
grpc-stubs = "^1.53"
17+
types-protobuf = ">=4.21"
18+
1519
[tool.poetry.group.lint.dependencies]
1620
bandit = { version = ">=1.7", extras = ["toml"] }
1721
ni-python-styleguide = ">=0.4.1"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
"""
2+
@generated by mypy-protobuf. Do not edit manually!
3+
isort:skip_file
4+
"""
5+
6+
import abc
7+
import collections.abc
8+
import grpc
9+
import grpc.aio
10+
import ni.pythonpanel.v1.python_panel_service_pb2
11+
import typing
12+
13+
_T = typing.TypeVar("_T")
14+
15+
class _MaybeAsyncIterator(collections.abc.AsyncIterator[_T], collections.abc.Iterator[_T], metaclass=abc.ABCMeta): ...
16+
17+
class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ignore[misc, type-arg]
18+
...
19+
20+
class PythonPanelServiceStub:
21+
"""Service interface for connecting to python panels"""
22+
23+
def __init__(self, channel: typing.Union[grpc.Channel, grpc.aio.Channel]) -> None: ...
24+
Connect: grpc.UnaryUnaryMultiCallable[
25+
ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest,
26+
ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse,
27+
]
28+
"""Connect to a panel and open it
29+
Status Codes for errors:
30+
- NOT_FOUND: the file for the panel was not found
31+
"""
32+
33+
Disconnect: grpc.UnaryUnaryMultiCallable[
34+
ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest,
35+
ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse,
36+
]
37+
"""Disconnect from a panel (does not close the panel)
38+
Status Codes for errors:
39+
- NOT_FOUND: the panel with the specified id was not found
40+
"""
41+
42+
GetValue: grpc.UnaryUnaryMultiCallable[
43+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
44+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse,
45+
]
46+
"""Get a value for a control on the panel
47+
Status Codes for errors:
48+
- NOT_FOUND: the panel with the specified id was not found
49+
"""
50+
51+
SetValue: grpc.UnaryUnaryMultiCallable[
52+
ni.pythonpanel.v1.python_panel_service_pb2.SetValueRequest,
53+
ni.pythonpanel.v1.python_panel_service_pb2.SetValueResponse,
54+
]
55+
"""Set a value for a control on the panel
56+
Status Codes for errors:
57+
- NOT_FOUND: the panel with the specified id was not found
58+
"""
59+
60+
class PythonPanelServiceAsyncStub:
61+
"""Service interface for connecting to python panels"""
62+
63+
Connect: grpc.aio.UnaryUnaryMultiCallable[
64+
ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest,
65+
ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse,
66+
]
67+
"""Connect to a panel and open it
68+
Status Codes for errors:
69+
- NOT_FOUND: the file for the panel was not found
70+
"""
71+
72+
Disconnect: grpc.aio.UnaryUnaryMultiCallable[
73+
ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest,
74+
ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse,
75+
]
76+
"""Disconnect from a panel (does not close the panel)
77+
Status Codes for errors:
78+
- NOT_FOUND: the panel with the specified id was not found
79+
"""
80+
81+
GetValue: grpc.aio.UnaryUnaryMultiCallable[
82+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
83+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse,
84+
]
85+
"""Get a value for a control on the panel
86+
Status Codes for errors:
87+
- NOT_FOUND: the panel with the specified id was not found
88+
"""
89+
90+
SetValue: grpc.aio.UnaryUnaryMultiCallable[
91+
ni.pythonpanel.v1.python_panel_service_pb2.SetValueRequest,
92+
ni.pythonpanel.v1.python_panel_service_pb2.SetValueResponse,
93+
]
94+
"""Set a value for a control on the panel
95+
Status Codes for errors:
96+
- NOT_FOUND: the panel with the specified id was not found
97+
"""
98+
99+
class PythonPanelServiceServicer(metaclass=abc.ABCMeta):
100+
"""Service interface for connecting to python panels"""
101+
102+
@abc.abstractmethod
103+
def Connect(
104+
self,
105+
request: ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest,
106+
context: _ServicerContext,
107+
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse]]:
108+
"""Connect to a panel and open it
109+
Status Codes for errors:
110+
- NOT_FOUND: the file for the panel was not found
111+
"""
112+
113+
@abc.abstractmethod
114+
def Disconnect(
115+
self,
116+
request: ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest,
117+
context: _ServicerContext,
118+
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse]]:
119+
"""Disconnect from a panel (does not close the panel)
120+
Status Codes for errors:
121+
- NOT_FOUND: the panel with the specified id was not found
122+
"""
123+
124+
@abc.abstractmethod
125+
def GetValue(
126+
self,
127+
request: ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
128+
context: _ServicerContext,
129+
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse]]:
130+
"""Get a value for a control on the panel
131+
Status Codes for errors:
132+
- NOT_FOUND: the panel with the specified id was not found
133+
"""
134+
135+
@abc.abstractmethod
136+
def SetValue(
137+
self,
138+
request: ni.pythonpanel.v1.python_panel_service_pb2.SetValueRequest,
139+
context: _ServicerContext,
140+
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.SetValueResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.SetValueResponse]]:
141+
"""Set a value for a control on the panel
142+
Status Codes for errors:
143+
- NOT_FOUND: the panel with the specified id was not found
144+
"""
145+
146+
def add_PythonPanelServiceServicer_to_server(servicer: PythonPanelServiceServicer, server: typing.Union[grpc.Server, grpc.aio.Server]) -> None: ...

src/nipanel/_panel.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import sys
44
from abc import ABC, abstractmethod
55
from types import TracebackType
6-
from typing import Optional, Type, TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Optional, Type
77

88
from grpc import RpcError, StatusCode, insecure_channel
9-
from ni.pythonpanel.v1.python_panel_service_pb2 import ConnectRequest
10-
from ni.pythonpanel.v1.python_panel_service_pb2 import DisconnectRequest
9+
from ni.pythonpanel.v1.python_panel_service_pb2 import ConnectRequest, DisconnectRequest
1110
from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub
1211

1312
from nipanel._panel_not_found_error import PanelNotFoundError
@@ -63,10 +62,7 @@ def connect(self) -> None:
6362
# TODO: use the channel pool
6463
channel = insecure_channel(self._get_channel_url())
6564
self._stub = PythonPanelServiceStub(channel)
66-
67-
connect_request = ConnectRequest(
68-
panel_id=self._panel_id, panel_uri=self._panel_uri
69-
)
65+
connect_request = ConnectRequest(panel_id=self._panel_id, panel_uri=self._panel_uri)
7066

7167
try:
7268
self._stub.Connect(connect_request)
@@ -82,7 +78,7 @@ def disconnect(self) -> None:
8278

8379
if self._stub is None:
8480
raise RuntimeError("connect() must be called before disconnect()")
85-
81+
8682
try:
8783
self._stub.Disconnect(disconnect_request)
8884
except RpcError as e:

tests/unit/test_panel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def test___connected_panel___set_value___gets_same_value() -> None:
2020

2121
def test___with_panel___set_value___gets_same_value() -> None:
2222
with nipanel.StreamlitPanel("my_panel", "path/to/script") as panel:
23-
2423
panel.set_value("test_id", "test_value")
2524

2625
# TODO: AB#3095681 - change asserted value to test_value

0 commit comments

Comments
 (0)