Skip to content

Commit 0859350

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup and tests
1 parent 461d6cf commit 0859350

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/nipanel/_panel_client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import pathlib
45
import threading
56
from typing import Callable, TypeVar
67

@@ -51,8 +52,8 @@ def start_streamlit_panel(
5152
self, panel_id: str, panel_script_path: str, python_interpreter_path: str
5253
) -> str:
5354

54-
panel_script_url = self._to_file_url(panel_script_path)
55-
python_interpreter_url = self._to_file_url(python_interpreter_path)
55+
panel_script_url = pathlib.Path(panel_script_path).absolute().as_uri()
56+
python_interpreter_url = pathlib.Path(python_interpreter_path).absolute().as_uri()
5657
streamlit_panel_configuration = StreamlitPanelConfiguration(
5758
panel_script_url=panel_script_url, python_interpreter_url=python_interpreter_url
5859
)
@@ -131,6 +132,3 @@ def _invoke_with_retry(
131132
self._stub = None
132133
return method(*args, **kwargs)
133134
raise
134-
135-
def _to_file_url(self, path: str) -> str:
136-
return path if path.startswith("file://") else f"file://{path}"

tests/unit/test_streamlit_panel.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,25 @@ def test___panel___panel_is_running_and_in_memory(
509509
assert is_panel_running(panel)
510510

511511

512-
def test___panel___python_path_is_in_venv(
512+
def test___panel___python_interpreter_url_is_in_venv(
513513
fake_python_panel_service: FakePythonPanelService,
514514
fake_panel_channel: grpc.Channel,
515515
) -> None:
516516
StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)
517517

518+
assert fake_python_panel_service.servicer.python_interpreter_url.startswith("file://")
518519
assert ".venv" in fake_python_panel_service.servicer.python_interpreter_url
519520

520521

522+
def test___panel___python_script_url_starts_with_file(
523+
fake_python_panel_service: FakePythonPanelService,
524+
fake_panel_channel: grpc.Channel,
525+
) -> None:
526+
StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)
527+
528+
assert fake_python_panel_service.servicer.python_script_url.startswith("file://")
529+
530+
521531
def is_panel_in_memory(panel: StreamlitPanel) -> bool:
522532
return panel.panel_id in panel._panel_client.enumerate_panels().keys()
523533

tests/utils/_fake_python_panel_servicer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self) -> None:
3232
self._set_count: int = 0
3333
self._notification_count: int = 0
3434
self._python_interpreter_url: str = ""
35+
self._python_script_url: str = ""
3536

3637
def StartPanel( # noqa: N802
3738
self, request: StartPanelRequest, context: Any
@@ -40,6 +41,7 @@ def StartPanel( # noqa: N802
4041
streamlit_panel_configuration = StreamlitPanelConfiguration()
4142
request.panel_configuration.Unpack(streamlit_panel_configuration)
4243
self._python_interpreter_url = streamlit_panel_configuration.python_interpreter_url
44+
self._python_script_url = streamlit_panel_configuration.panel_script_url
4345
if self._fail_next_start_panel:
4446
self._fail_next_start_panel = False
4547
context.abort(grpc.StatusCode.UNAVAILABLE, "Simulated failure")
@@ -106,9 +108,14 @@ def notification_count(self) -> int:
106108

107109
@property
108110
def python_interpreter_url(self) -> str:
109-
"""Get the Python path used to start the panel."""
111+
"""Get the Python interpreter url."""
110112
return self._python_interpreter_url
111113

114+
@property
115+
def python_script_url(self) -> str:
116+
"""Get the Python script url."""
117+
return self._python_script_url
118+
112119
def _init_panel(self, panel_id: str) -> None:
113120
if panel_id not in self._panel_ids:
114121
self._panel_ids.append(panel_id)

0 commit comments

Comments
 (0)