-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add plotly-express JsPlugin implementation and registration (#150)
This plumbs automatic JsPlugin registration - the server side depends on deephaven/deephaven-core#4925.
- Loading branch information
1 parent
04321a0
commit d6d0416
Showing
5 changed files
with
104 additions
and
27 deletions.
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 | ||
""" | ||
callback.register(DeephavenFigureType) | ||
callback.register(create_js_plugin()) |