Skip to content

Commit 628d03a

Browse files
Mike ProsserMike Prosser
authored andcommitted
_PanelClient should not be public
1 parent 85f9835 commit 628d03a

File tree

3 files changed

+6
-95
lines changed

3 files changed

+6
-95
lines changed

src/nipanel/_panel_client.py

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Client for accessing the NI Python Panel Service."""
2-
31
from __future__ import annotations
42

53
import logging
@@ -31,9 +29,7 @@
3129
_logger = logging.getLogger(__name__)
3230

3331

34-
class PanelClient:
35-
"""Client for accessing the NI Python Panel Service."""
36-
32+
class _PanelClient:
3733
def __init__(
3834
self,
3935
*,
@@ -43,15 +39,6 @@ def __init__(
4339
grpc_channel_pool: GrpcChannelPool | None = None,
4440
grpc_channel: grpc.Channel | None = None,
4541
) -> None:
46-
"""Initialize the panel client.
47-
48-
Args:
49-
provided_interface: The interface provided by the service.
50-
service_class: The class of the service.
51-
discovery_client: An optional discovery client.
52-
grpc_channel: An optional panel gRPC channel.
53-
grpc_channel_pool: An optional gRPC channel pool.
54-
"""
5542
self._initialization_lock = threading.Lock()
5643
self._provided_interface = provided_interface
5744
self._service_class = service_class
@@ -61,51 +48,17 @@ def __init__(
6148
self._stub: PythonPanelServiceStub | None = None
6249

6350
def start_panel(self, panel_id: str, panel_script_path: str, python_path: str) -> str:
64-
"""Start the panel.
65-
66-
Args:
67-
panel_id: The ID of the panel to start.
68-
panel_script_path: The path of the panel script file.
69-
python_path: The path to the Python executable.
70-
71-
Returns:
72-
The URL of the panel.
73-
74-
Raises:
75-
grpc.RpcError: With status code:
76-
- INVALID_ARGUMENT: If the panel script filename doesn't end in .py, or
77-
if the panel identifier contains invalid characters (only alphanumeric
78-
characters and underscores are allowed).
79-
- NOT_FOUND: If the panel script file or Python executable file was not found.
80-
"""
8151
start_panel_request = StartPanelRequest(
8252
panel_id=panel_id, panel_script_path=panel_script_path, python_path=python_path
8353
)
8454
response = self._invoke_with_retry(self._get_stub().StartPanel, start_panel_request)
8555
return response.panel_url
8656

8757
def stop_panel(self, panel_id: str, reset: bool) -> None:
88-
"""Stop the panel.
89-
90-
Args:
91-
panel_id: The ID of the panel to stop.
92-
reset: Whether to reset all storage associated with panel.
93-
94-
Raises:
95-
grpc.RpcError: With status code:
96-
- INVALID_ARGUMENT: If the panel identifier contains invalid characters
97-
(only alphanumeric characters and underscores are allowed).
98-
"""
9958
stop_panel_request = StopPanelRequest(panel_id=panel_id, reset=reset)
10059
self._invoke_with_retry(self._get_stub().StopPanel, stop_panel_request)
10160

10261
def enumerate_panels(self) -> dict[str, tuple[str, list[str]]]:
103-
"""Enumerate all available panels.
104-
105-
Returns:
106-
A dictionary mapping panel IDs to a tuple containing the url of the panel (if it is
107-
running) and a list of value IDs associated with the panel.
108-
"""
10962
enumerate_panels_request = EnumeratePanelsRequest()
11063
response = self._invoke_with_retry(
11164
self._get_stub().EnumeratePanels, enumerate_panels_request
@@ -115,60 +68,18 @@ def enumerate_panels(self) -> dict[str, tuple[str, list[str]]]:
11568
}
11669

11770
def set_value(self, panel_id: str, value_id: str, value: object, notify: bool) -> None:
118-
"""Set the value for the control with value_id.
119-
120-
Args:
121-
panel_id: The ID of the panel.
122-
value_id: The ID of the control.
123-
value: The value to set.
124-
notify: Whether to notify other clients of the new value.
125-
126-
Raises:
127-
grpc.RpcError: With status code:
128-
- INVALID_ARGUMENT: If the panel identifier or value identifier contains
129-
invalid characters (only alphanumeric characters and underscores are allowed).
130-
"""
13171
new_any = to_any(value)
13272
set_value_request = SetValueRequest(
13373
panel_id=panel_id, value_id=value_id, value=new_any, notify=notify
13474
)
13575
self._invoke_with_retry(self._get_stub().SetValue, set_value_request)
13676

13777
def get_value(self, panel_id: str, value_id: str) -> object:
138-
"""Get the value for the control with value_id.
139-
140-
Args:
141-
panel_id: The ID of the panel.
142-
value_id: The ID of the control.
143-
144-
Returns:
145-
The value.
146-
147-
Raises:
148-
grpc.RpcError: With status code:
149-
- INVALID_ARGUMENT: If the panel identifier or value identifier contains
150-
invalid characters (only alphanumeric characters and underscores are allowed).
151-
- NOT_FOUND: If the value with the specified identifier was not found.
152-
"""
15378
get_value_request = GetValueRequest(panel_id=panel_id, value_id=value_id)
15479
response = self._invoke_with_retry(self._get_stub().GetValue, get_value_request)
15580
return from_any(response.value)
15681

15782
def try_get_value(self, panel_id: str, value_id: str) -> object | None:
158-
"""Try to get the value for the control with value_id.
159-
160-
Args:
161-
panel_id: The ID of the panel.
162-
value_id: The ID of the control.
163-
164-
Returns:
165-
The value if found, otherwise None.
166-
167-
Raises:
168-
grpc.RpcError: With status code:
169-
- INVALID_ARGUMENT: If the panel identifier or value identifier contains
170-
invalid characters (only alphanumeric characters and underscores are allowed).
171-
"""
17283
try_get_value_request = TryGetValueRequest(panel_id=panel_id, value_id=value_id)
17384
response = self._invoke_with_retry(self._get_stub().TryGetValue, try_get_value_request)
17485
if response.HasField("value"):

src/nipanel/_panel_value_accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
1010
from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool
1111

12-
from nipanel._panel_client import PanelClient
12+
from nipanel._panel_client import _PanelClient
1313

1414
_T = TypeVar("_T")
1515

@@ -37,7 +37,7 @@ def __init__(
3737
grpc_channel: grpc.Channel | None = None,
3838
) -> None:
3939
"""Initialize the accessor."""
40-
self._panel_client = PanelClient(
40+
self._panel_client = _PanelClient(
4141
provided_interface=provided_interface,
4242
service_class=service_class,
4343
discovery_client=discovery_client,

tests/unit/test_panel_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import grpc
22
import pytest
33

4-
from nipanel._panel_client import PanelClient
4+
from nipanel._panel_client import _PanelClient
55

66

77
def test___enumerate_is_empty(fake_panel_channel: grpc.Channel) -> None:
@@ -86,8 +86,8 @@ def test___set_value___gets_value(fake_panel_channel: grpc.Channel) -> None:
8686
assert client.try_get_value("panel1", "val1") == "value1"
8787

8888

89-
def create_panel_client(fake_panel_channel: grpc.Channel) -> PanelClient:
90-
return PanelClient(
89+
def create_panel_client(fake_panel_channel: grpc.Channel) -> _PanelClient:
90+
return _PanelClient(
9191
provided_interface="iface",
9292
service_class="svc",
9393
grpc_channel=fake_panel_channel,

0 commit comments

Comments
 (0)