Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jnumainville committed May 7, 2024
1 parent 2aad1d6 commit db4c1c8
Show file tree
Hide file tree
Showing 36 changed files with 88 additions and 25 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# templates cannot be properly checked for formatting due to the substitution syntax
exclude: templates
repos:
- repo: https://github.com/adamchainz/blacken-docs
Expand Down
2 changes: 1 addition & 1 deletion templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cookiecutter gh:deephaven/deephaven-plugins --directory="templates/<template nam

Currently, we offer the following templates:

## bidirectional-widget-plugin
## widget

This creates a basic bidirectional widget plugin for Deephaven.
A bidirectional plugin can send and receive messages on both the client and server.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"project_name": "deephaven_plugin_template",
"python_project_name": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}",
"javascript_project_name": "{{ cookiecutter.project_name.lower().replace('_', '-') }}",
"python_project_name": "deephaven_plugin_template",
"javascript_project_name": "{{ cookiecutter.python_project_name.lower().replace('_', '-') }}",
"author_name": "Anonymous",
"author_email": "Anonymous",
"__py_namespace": "{{ cookiecutter.python_project_name }}",
Expand Down
6 changes: 6 additions & 0 deletions templates/widget/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

python_project_name = '{{ cookiecutter.python_project_name }}'

if not python_project_name.isidentifier():
raise ValueError(f'{python_project_name} is not a valid Python project name')
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# {{ cookiecutter.project_name }}
# {{ cookiecutter.python_project_name }}

This is a Python plugin for Deephaven generated from a [deephaven-plugin](https://github.com/deephaven/deephaven-plugins) template.

Expand Down Expand Up @@ -54,7 +54,14 @@ The built wheel file will be located in the `dist` directory.
## Installing the Plugin

The plugin can be installed into a Deephaven instance with `pip install <wheel file>`.
The wheel file is stored in the `dist` directory after building the plugin.
Exactly how this is done will depend on how you are running Deephaven.
If using the venv created above, the plugin and server can be created with the following commands:
```sh
pip install deephaven-server
pip install dist/{{ cookiecutter.python_project_name }}-0.0.1-py3-none-any.whl
deephaven server
```
See the [plug-in documentation](https://deephaven.io/core/docs/how-to-guides/use-plugins/) for more information.

## Using the Plugin
Expand All @@ -72,3 +79,10 @@ A panel should appear. You can now use the object to send messages to the client
```python
obj.send_message("Hello, world!")
```

The panel can also send messages back to the Python client by using the input field.

## Distributing the Plugin
To distribute the plugin, you can upload the wheel file to a package repository, such as [PyPI](https://pypi.org/).
The version of the plugin can be updated in the `setup.cfg` file.
See the [Python packaging documentation](https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives) for more information.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from setuptools import setup
import shutil
import os
from deephaven.plugin.packaging import package_js

# remove the build directory to ensure that the package is built from the latest js files
try:
shutil.rmtree("build")
except FileNotFoundError:
pass

# js_dir is the directory where the JavaScript source files are located
js_dir = "src/js/"
# dest_dir is the directory where the JavaScript source files will be copied to in the package
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.13.0
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
"@deephaven/jsapi-bootstrap": "^0.58.0",
"@deephaven/jsapi-types": "^0.58.0",
"@deephaven/log": "^0.58.0",
"@deephaven/plugin": "^0.58.0",
"shortid": "^2.2.16"
"@deephaven/plugin": "^0.58.0"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist/index.js"
]
],
"engines": {
"node": "18.13.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ export const {{ cookiecutter.__js_plugin_view_obj_style }}: CSSProperties = {
justifyContent: "center",
alignItems: "center",
height: "100%",
width: "100%"
width: "100%",
flexDirection: "column"
};

export function {{ cookiecutter.__js_plugin_view_obj }}(props: WidgetComponentProps): JSX.Element {
const { fetch } = props;
const [text, setText] = useState<string>("Call send_message on the object and the message will appear here.");
const [formText, setFormText] = useState('');
const [widget, setWidget] = useState<Widget | null>(null);
const dh = useApi();

useEffect(() => {
async function init() {
// Fetch the widget from the server
const widget = await fetch();
const fetched_widget = await fetch();
setWidget(fetched_widget);


// Add an event listener to the widget to listen for messages from the server
widget.addEventListener<Widget>(
fetched_widget.addEventListener<Widget>(
dh.Widget.EVENT_MESSAGE,
({ detail }) => {
// When a message is received, update the text in the component
const text = detail.getDataAsString();
if (text) {
setText(text);
widget.sendMessage("message acknowledged", []);
}
}
);
Expand All @@ -45,8 +49,25 @@ export function {{ cookiecutter.__js_plugin_view_obj }}(props: WidgetComponentPr
}, [dh, fetch]);

return (
<div className="{{ cookiecutter.__js_plugin_view_class }}" style={{ "{" }}{{ cookiecutter.__js_plugin_view_obj_style }}{{ "}" }}>
{text}
<div style={{ "{" }}{{ cookiecutter.__js_plugin_view_obj_style }}{{ "}" }}>
<div>{text}</div>
<div>Send a message to the server:</div>
<div>
<input
type="text"
value={formText}
onChange={(e) => setFormText(e.target.value)}
/>
<button
onClick={() => {
// Send the message to the server via the widget
fetch().then((widget) => {
widget.sendMessage(formText, []);
});
}}>
Send
</button>
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export default defineConfig(({ mode }) => ({
'react-dom',
'redux',
'react-redux',
// Externalize all Deephaven dependencies to reduce bundle size and maintain proper context for themes, etc.
'@deephaven/jsapi-bootstrap',
'@deephaven/components',
'@deephaven/dashboard',
'@deephaven/icons',
'@deephaven/jsapi-bootstrap',
'@deephaven/jsapi-types',
'@deephaven/log',
'@deephaven/plugin'
],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is where built js files are stored by setup.py
_js/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
This is a plugin for Deephaven that provides a simple object that can send messages to and from the client.
"""

from .{{ cookiecutter.__object_file_name }} import *
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

from deephaven.plugin.object_type import MessageStream

# This is a simple object that demonstrates how to send messages to the client.
# When the object is created, it will be passed a connection to the client.
# This connection can be used to send messages back to the client.
class {{ cookiecutter.__object_name }}:
"""
This is a simple object that demonstrates how to send messages to the client.
When the object is created, it will be passed a connection to the client.
This connection can be used to send messages back to the client.
Attributes:
_connection: MessageStream: The connection to the client
"""
def __init__(self):
self._connection: MessageStream = None

Expand Down

0 comments on commit db4c1c8

Please sign in to comment.