-
Couldn't load subscription status.
- Fork 0
Implement Task AB#3095678 - Define Measurement Script API #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4634cbc
first draft
9c901fc
add basic tests
5511c58
cleanup
eaf0bc3
address feedback
9b5c99f
refactor to use _StreamlitPanel subclass
5034907
refactor to make StreamlitPanel public instead of Panel
166774d
make Panel public also, for type hints
92d200d
panel_id should be specified by the user. Also, lets provide readonly…
f4d4a52
put panel_id berfore panel_uri
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "python.testing.pytestArgs": [ | ||
| "tests" | ||
| ], | ||
| "python.testing.unittestEnabled": false, | ||
| "python.testing.pytestEnabled": true | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| """The NI Panel.""" | ||
|
|
||
| from nipanel.nipanel import NiPanel | ||
|
|
||
| __all__ = ["NiPanel"] | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
mikeprosserni marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """NI Panel.""" | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import uuid | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from types import TracebackType | ||
| from typing import Optional, Type | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class NiPanel: | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """This class allows you to access controls on the panel.""" | ||
|
|
||
| def __init__(self) -> None: | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Initialize the NiPanel instance.""" | ||
| self._stub = None # will be a PythonPanelServiceStub | ||
| self.panel_uri = "" | ||
| self.panel_id = "" | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def __enter__(self) -> "NiPanel": | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Enter the runtime context related to this object.""" | ||
| self.connect() | ||
| return self | ||
|
|
||
| def __exit__( | ||
| self, | ||
| exctype: Optional[Type[BaseException]], | ||
| excinst: Optional[BaseException], | ||
| exctb: Optional[TracebackType], | ||
| ) -> Optional[bool]: | ||
| """Exit the runtime context related to this object.""" | ||
| self.disconnect() | ||
| return None | ||
|
|
||
| @classmethod | ||
| def streamlit_panel(cls, streamlit_script_path: str) -> "NiPanel": | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Create a panel using a streamlit script for the user interface. | ||
| Args: | ||
| streamlit_script_path: The file path of the streamlit script | ||
| Returns: | ||
| NiPanel: A new panel associated with the streamlit script | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| panel = cls() | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| panel.panel_uri = streamlit_script_path | ||
| panel.panel_id = str(uuid.uuid4()) | ||
| return panel | ||
|
|
||
| def connect(self) -> None: | ||
| """Connect to the panel and open it.""" | ||
| # TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect | ||
| pass | ||
|
|
||
| def disconnect(self) -> None: | ||
| """Disconnect from the panel (does not close the panel).""" | ||
| # TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect | ||
| pass | ||
|
|
||
| def get_value(self, value_id: str) -> object: | ||
| """Get the value for a control on the panel. | ||
| Args: | ||
| value_id: The id of the value | ||
| Returns: | ||
| object: The value | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| # TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type | ||
| return "placeholder value" | ||
|
|
||
| def set_value(self, value_id: str, value: object) -> None: | ||
| """Set the value for a control on the panel. | ||
| Args: | ||
| value_id: The id of the value | ||
| value: The value | ||
| """ | ||
| # TODO: AB#3095681 - Convert the value to an Any and pass it to _stub.SetValue | ||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for the `nipanel` package.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from nipanel import NiPanel | ||
|
|
||
|
|
||
| def test_streamlit_panel() -> None: | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| panel = NiPanel.streamlit_panel("path/to/script") | ||
| assert panel.panel_uri == "path/to/script" | ||
| assert panel.panel_id is not None | ||
| panel.connect() | ||
| panel.set_value("test_id", "test_value") | ||
| assert panel.get_value("test_id") == "placeholder value" | ||
| panel.disconnect() | ||
|
|
||
|
|
||
| def test_with_streamlit_panel() -> None: | ||
| with NiPanel.streamlit_panel("path/to/script") as panel: | ||
| assert panel.panel_uri == "path/to/script" | ||
| assert panel.panel_id is not None | ||
| panel.set_value("test_id", "test_value") | ||
| assert panel.get_value("test_id") == "placeholder value" | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.