Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jnumainville committed Apr 24, 2024
1 parent 61d639f commit bf068a6
Show file tree
Hide file tree
Showing 30 changed files with 47 additions and 43 deletions.
21 changes: 14 additions & 7 deletions templates/bidirectional-plugin/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"project_name": "deephaven plugin template",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}",
"py_namespace": "plugins.{{cookiecutter.project_slug}}",
"py_folder_name": "plugins/{{cookiecutter.project_slug}}",
"py_pascal_case": "{{ cookiecutter.project_name.title().replace(' ', '') }}",
"py_kebab_case": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
"object_name": "plugins.{{ cookiecutter.py_pascal_case }}",
"python_project_name": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}",
"javascript_project_name": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
"author_name": "Anonymous",
"author_email": "Anonymous"
"author_email": "Anonymous",
"__py_namespace": "{{ cookiecutter.python_project_name }}",
"__src_folder_name": "{{ cookiecutter.python_project_name }}",
"__name_pascal_case": "{{ cookiecutter.python_project_name.replace('_', ' ') .title().replace(' ', '') }}",
"__registered_object_name": "{{ cookiecutter.__name_pascal_case }}",
"__object_name": "{{ cookiecutter.__name_pascal_case }}Object",
"__object_file_name": "{{ cookiecutter.python_project_name }}_object",
"__type_name": "{{ cookiecutter.__name_pascal_case }}Type",
"__type_file_name": "{{ cookiecutter.python_project_name }}_type",
"__message_stream_name": "{{ cookiecutter.__name_pascal_case }}MessageStream",
"__js_plugin_obj_name": "{{ cookiecutter.__name_pascal_case }}JsPlugin",
"__registration_name": "{{ cookiecutter.__name_pascal_case }}Registration"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[metadata]
name = {{cookiecutter.project_name}}
name = {{cookiecutter.python_project_name}}
description = deephaven plugin
long_description = file: README.md
long_description_content_type = text/markdown
version = 0.0.1.dev0
keywords = deephaven, plugin, graph
author = {{cookiecutter.author_name}}
author_email = {{cookiecutter.author_email}}
author = {{ cookiecutter.author_name }}
author_email = {{ cookiecutter.author_email }}
platforms = any

[options]
Expand All @@ -24,4 +24,4 @@ where=src

[options.entry_points]
deephaven.plugin =
registration_cls = {{cookiecutter.py_namespace}}._register:{{cookiecutter.py_pascal_case}}Registration
registration_cls = {{ cookiecutter.__py_namespace }}._register:{{ cookiecutter.__registration_name }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from deephaven.plugin.packaging import package_js

js_dir = "src/js/"
dest_dir = os.path.join("src/{{cookiecutter.py_folder_name}}/_js")
dest_dir = os.path.join("src/{{cookiecutter.__src_folder_name}}/_js")

package_js(js_dir, dest_dir)

setup(package_data={"{{cookiecutter.py_namespace}}._js": ["**"]})
setup(package_data={"{{cookiecutter.__py_namespace}}._js": ["**"]})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "@deephaven/{{ cookiecutter.py_kebab_case }}",
"name": "{{ cookiecutter.javascript_project_name }}",
"version": "0.1.0",
"description": "Deephaven plugin",
"description": "A plugin for deephaven",
"keywords": [
"Deephaven",
"plugin",
"deephaven-js-plugin"
"plugin"
],
"author": "{{ cookiecutter.author_name }}",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { DashboardPanelProps } from '@deephaven/dashboard';
import Log from '@deephaven/log';

const log = Log.module('@deephaven/{{ cookiecutter.py_kebab_case }}.CustomPanel');
const log = Log.module('{{ cookiecutter.javascript_project_name }}.CustomPanel');

/**
* Displays a custom panel. Props passed in are determined by your `DashboardPlugin` that registers this panel.
Expand All @@ -11,6 +11,6 @@ export function CustomPanel(props: DashboardPanelProps): JSX.Element {
return <div className="custom-panel">This is a custom panel</div>;
}

CustomPanel.COMPONENT = '@deephaven/{{ cookiecutter.py_kebab_case }}.CustomPanel';
CustomPanel.COMPONENT = '{{ cookiecutter.javascript_project_name }}.CustomPanel';

export default CustomPanel;
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import styles from './CustomPanel.scss?inline';
/**
* Create your own logger module to easily identify where logs are being printed from.
*/
const log = Log.module('@deephaven/{{ cookiecutter.py_kebab_case }}.DashboardPlugin');
const log = Log.module('{{ cookiecutter.javascript_project_name }}.DashboardPlugin');

/**
* Specify a plugin matching an expected custom object type to react to when that object type is opened.
*/
export const VARIABLE_TYPE = '{{ cookiecutter.object_name }}';
export const VARIABLE_TYPE = '{{ cookiecutter.__registered_object_name }}';

/**
* Dashboard Plugin. Registers with a dashboard. The rendered component will be rendered atop the dashboard layout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
The API is designed to be similar to React, but with some differences to make it more Pythonic.
"""

from .{{cookiecutter.project_slug}}_object import *
from .{{ cookiecutter.__object_file_name }} import *
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from deephaven.plugin.js import JsPlugin


class {{cookiecutter.py_pascal_case}}JsPlugin(JsPlugin):
class {{ cookiecutter.__js_plugin_obj_name }}(JsPlugin):
def __init__(
self,
name: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from deephaven.plugin import Registration, Callback
from deephaven.plugin.utilities import create_js_plugin, DheSafeCallbackWrapper

from ._js_plugin import {{ cookiecutter.py_pascal_case }}JsPlugin
from .{{ cookiecutter.project_slug }}_type import {{ cookiecutter.py_pascal_case }}Type
from ._js_plugin import {{ cookiecutter.__js_plugin_obj_name }}
from .{{ cookiecutter.__type_file_name }} import {{ cookiecutter.__type_name }}

PACKAGE_NAMESPACE = "{{cookiecutter.py_namespace}}"
PACKAGE_NAMESPACE = "{{cookiecutter.__py_namespace}}"
JS_NAME = "_js"
PLUGIN_CLASS = {{cookiecutter.py_pascal_case}}JsPlugin
PLUGIN_CLASS = {{ cookiecutter.__js_plugin_obj_name }}


class {{ cookiecutter.py_pascal_case }}Registration(Registration):
class {{ cookiecutter.__registration_name }}(Registration):
@classmethod
def register_into(cls, callback: Callback) -> None:

callback = DheSafeCallbackWrapper(callback)

callback.register({{ cookiecutter.py_pascal_case }}Type)
callback.register({{ cookiecutter.__type_name }})

js_plugin = create_js_plugin(
PACKAGE_NAMESPACE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

class {{cookiecutter.py_pascal_case}}Object:
class {{ cookiecutter.__object_name }}:
def __init__(self):
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
from typing import Any
from deephaven.plugin.object_type import MessageStream, BidirectionalObjectType

from .{{cookiecutter.project_slug}}_object import {{cookiecutter.py_pascal_case}}Object
from .{{ cookiecutter.__object_file_name }} import {{ cookiecutter.__object_name }}

class {{cookiecutter.py_pascal_case}}MessageStream(MessageStream):
class {{ cookiecutter.__message_stream_name }}(MessageStream):
"""
Connection for DeephavenFigure
A custom MessageStream
Attributes:
_listener: DeephavenFigureListener: The listener for the figure
_client_connection: MessageStream: The connection to the client
"""

def __init__(self, obj, client_connection: MessageStream):
def __init__(self, obj: Any, client_connection: MessageStream):
super().__init__()
self._client_connection = client_connection

Expand All @@ -36,21 +35,20 @@ def on_close(self) -> None:
pass


class {{cookiecutter.py_pascal_case}}Type(BidirectionalObjectType):
class {{ cookiecutter.__type_name }}(BidirectionalObjectType):
"""
Defines the Element type for the Deephaven plugin system.
"""

@property
def name(self) -> str:
return "{{ cookiecutter.object_name }}"
return "{{ cookiecutter.__registered_object_name }}"

def is_type(self, obj: Any) -> bool:
return isinstance(obj, {{cookiecutter.py_pascal_case}}Object)
return isinstance(obj, {{ cookiecutter.__object_name }})

def create_client_connection(
self, obj: object, connection: MessageStream
) -> MessageStream:
message_stream = {{cookiecutter.py_pascal_case}}MessageStream(obj, connection)
#message_stream.on_data(payload, references)
message_stream = {{ cookiecutter.__message_stream_name }}(obj, connection)
return message_stream
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Test(BaseTestCase):
def test_is_table(self):
def test(self):
# since the tests use the embedded server, the import must happen after the tests start
from deephaven import Table

Expand Down

0 comments on commit bf068a6

Please sign in to comment.