-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Add plotly-express JsPlugin implementation and registration #150
Merged
devinrsmith
merged 8 commits into
deephaven:main
from
devinrsmith:plotly-express-js-plugin
Dec 20, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7e1109
feat: Add plotly-express JsPlugin implementation and registration
devinrsmith 79143d3
Update to source from NPM package
devinrsmith 786b378
Add python 3.8 support
devinrsmith 2609d44
Update comments
devinrsmith c400a96
Update typing to ContextManager
devinrsmith 2f58734
Update for deephaven-plugin==0.6.0
devinrsmith 5c56fe5
Merge remote-tracking branch 'upstream/main' into plotly-express-js-p…
devinrsmith ade4c8a
Refactor to move registration and js to internal packages
devinrsmith 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 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
This file contains 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
This file contains 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
This file contains 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,73 @@ | ||
import importlib.resources | ||
import json | ||
import pathlib | ||
import sys | ||
from typing import Callable, ContextManager | ||
|
||
from deephaven.plugin.js import JsPlugin | ||
|
||
|
||
class ExpressJsPlugin(JsPlugin): | ||
def __init__( | ||
self, | ||
name: str, | ||
version: str, | ||
main: str, | ||
path: pathlib.Path, | ||
) -> None: | ||
self._name = name | ||
self._version = version | ||
self._main = main | ||
self._path = path | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def version(self) -> str: | ||
return self._version | ||
|
||
@property | ||
def main(self) -> str: | ||
return self._main | ||
|
||
def path(self) -> pathlib.Path: | ||
return self._path | ||
|
||
|
||
def _create_from_npm_package_json( | ||
path_provider: Callable[[], ContextManager[pathlib.Path]] | ||
) -> JsPlugin: | ||
with path_provider() as tmp_js_path: | ||
js_path = tmp_js_path | ||
if not js_path.exists(): | ||
raise Exception( | ||
f"Package is not installed in a normal python filesystem, '{js_path}' does not exist" | ||
) | ||
with (js_path / "package.json").open("rb") as f: | ||
package_json = json.load(f) | ||
return ExpressJsPlugin( | ||
package_json["name"], | ||
package_json["version"], | ||
package_json["main"], | ||
js_path, | ||
) | ||
|
||
|
||
def _resource_js_path() -> ContextManager[pathlib.Path]: | ||
# TODO: Js content should be in same package directory | ||
# https://github.com/deephaven/deephaven-plugins/issues/139 | ||
if sys.version_info < (3, 9): | ||
return importlib.resources.path("js", "plotly-express") | ||
else: | ||
return importlib.resources.as_file( | ||
importlib.resources.files("js").joinpath("plotly-express") | ||
) | ||
|
||
|
||
def create_js_plugin() -> JsPlugin: | ||
# TODO: Include developer instructions for installing in editable mode | ||
# https://github.com/deephaven/deephaven-plugins/issues/93 | ||
# TBD what editable mode looks like for JsPlugin | ||
return _create_from_npm_package_json(_resource_js_path) |
24 changes: 24 additions & 0 deletions
24
plugins/plotly-express/src/deephaven/plot/express/_register.py
This file contains 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,24 @@ | ||||
from . import DeephavenFigureType | ||||
from ._js import create_js_plugin | ||||
|
||||
from deephaven.plugin import Registration, Callback | ||||
|
||||
|
||||
class ExpressRegistration(Registration): | ||||
""" | ||||
Register the DeephavenFigureType and a JsPlugin | ||||
|
||||
""" | ||||
|
||||
@classmethod | ||||
def register_into(cls, callback: Callback) -> None: | ||||
""" | ||||
Register the DeephavenFigureType and a JsPlugin | ||||
|
||||
Args: | ||||
callback: Registration.Callback: | ||||
A function to call after registration | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
""" | ||||
callback.register(DeephavenFigureType) | ||||
callback.register(create_js_plugin()) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.