Repository: deephaven/deephaven-plugins (language: python)

Issue:
Remove startup when using embedded server
<!-- Please read our Code of Conduct: https://github.com/deephaven/deephaven-core/blob/main/CODE_OF_CONDUCT.md -->
<!-- Please search existing issues to avoid creating duplicates. -->

<!-- Describe the feature you'd like. -->
The server doesn't actually need to be started, we just need an instance for tests and building so the imports are resolved, so cleanup  `plotly-express`, `template` and for the `sphinx` `conf.py` as was done in #734 


Discussion / hints:

Fix patch:
diff --git a/plugins/plotly-express/conf.py b/plugins/plotly-express/conf.py
index f80ea1aae..e20cfdb4b 100644
--- a/plugins/plotly-express/conf.py
+++ b/plugins/plotly-express/conf.py
@@ -41,5 +41,5 @@
 
 from deephaven_server import Server
 
-s = Server(port=10075)
-s.start()
+# need a server instance to pull types from the autodocs
+Server(port=10075)
diff --git a/plugins/ui/conf.py b/plugins/ui/conf.py
index f80ea1aae..e20cfdb4b 100644
--- a/plugins/ui/conf.py
+++ b/plugins/ui/conf.py
@@ -41,5 +41,5 @@
 
 from deephaven_server import Server
 
-s = Server(port=10075)
-s.start()
+# need a server instance to pull types from the autodocs
+Server(port=10075)


Test patch:
diff --git a/plugins/plotly-express/test/__init__.py b/plugins/plotly-express/test/__init__.py
index e69de29bb..b29a4a041 100644
--- a/plugins/plotly-express/test/__init__.py
+++ b/plugins/plotly-express/test/__init__.py
@@ -0,0 +1,10 @@
+from deephaven_server.server import Server
+
+# Create a Server instance to initialize the JVM
+# Otherwise we get errors whenever we try to import anything or run tests
+# We don't even need to start the server, just create an instance.
+# https://github.com/deephaven/deephaven-core/blob/b5cae98c2f11b032cdd1b9c248dc5b4a0f95314a/py/embedded-server/deephaven_server/server.py#L152
+# Whenever you import anything from the deephaven namespace, it will check if the JVM is ready:
+# https://github.com/deephaven/deephaven-core/blob/b5cae98c2f11b032cdd1b9c248dc5b4a0f95314a/py/server/deephaven/__init__.py#L15
+if Server.instance is None:
+    Server(port=10000, jvm_args=["-Xmx4g"])
diff --git a/plugins/plotly-express/test/deephaven/plot/express/BaseTest.py b/plugins/plotly-express/test/deephaven/plot/express/BaseTest.py
index 6b1a88315..3f40a3da5 100644
--- a/plugins/plotly-express/test/deephaven/plot/express/BaseTest.py
+++ b/plugins/plotly-express/test/deephaven/plot/express/BaseTest.py
@@ -24,15 +24,6 @@ def remap_types(
 class BaseTestCase(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
-        try:
-            cls.s = Server(port=10000, jvm_args=["-Xmx4g"])
-            cls.s.start()
-        except Exception as e:
-            # server is already running
-            pass
-
-        # these mocks need to be setup after the deephaven server is
-        # initialized because they access the deephaven namespace
         cls.setup_exporter_mock()
 
     @classmethod
diff --git a/templates/widget/{{ cookiecutter.python_project_name }}/test/__init__.py b/templates/widget/{{ cookiecutter.python_project_name }}/test/__init__.py
index e69de29bb..8718e3915 100644
--- a/templates/widget/{{ cookiecutter.python_project_name }}/test/__init__.py
+++ b/templates/widget/{{ cookiecutter.python_project_name }}/test/__init__.py
@@ -0,0 +1,10 @@
+from deephaven_server.server import Server
+
+# Create a Server instance to initialize the JVM
+# Otherwise we get errors whenever we try to import anything or run tests
+# We don't even need to start the server, just create an instance.
+# https://github.com/deephaven/deephaven-core/blob/b5cae98c2f11b032cdd1b9c248dc5b4a0f95314a/py/embedded-server/deephaven_server/server.py#L152
+# Whenever you import anything from the deephaven namespace, it will check if the JVM is ready:
+# https://github.com/deephaven/deephaven-core/blob/b5cae98c2f11b032cdd1b9c248dc5b4a0f95314a/py/server/deephaven/__init__.py#L15
+if Server.instance is None:
+    Server(port=11000, jvm_args=["-Xmx4g"])
diff --git a/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/BaseTest.py b/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/BaseTest.py
index 81a9a3bb1..ee85249b3 100644
--- a/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/BaseTest.py
+++ b/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/BaseTest.py
@@ -7,16 +7,6 @@
 class BaseTestCase(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
-        try:
-            # Use port 11000 so it doesn't conflict with another server
-            cls.s = Server(port=11000, jvm_args=["-Xmx4g"])
-            cls.s.start()
-        except Exception as e:
-            # server is already running
-            pass
-
-        # these mocks need to be setup after the deephaven server is
-        # initialized because they access the deephaven namespace
         cls.setup_exporter_mock()
 
     @classmethod
diff --git a/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/test.py b/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/test.py
index 81b8a6bbc..f79744d33 100644
--- a/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/test.py
+++ b/templates/widget/{{ cookiecutter.python_project_name }}/test/{{ cookiecutter.python_project_name }}/test.py
@@ -5,7 +5,7 @@
 class Test(BaseTestCase):
     def test(self):
         # since the tests use the embedded server, the import must happen after the tests start
-        from deephaven import Table
+        from deephaven.table import Table
 
         pass