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

Issue:
Use standardized version metadata across python packages
Currently we define the versions for packages in a few different places. In some cases, we define it in the `__init__.py` file as `__version__`, in some cases we define it in the `setup.cfg` file.
Defining `__version__` is not recommended and was a [rejected PEP 396 standard](https://peps.python.org/pep-0396/#pep-rejection). Instead, we should define it in the `setup.cfg` or `pyproject.toml` file directly.


Discussion / hints:

Fix patch:
diff --git a/plugins/json/setup.cfg b/plugins/json/setup.cfg
index db54ea426..362d8bbb4 100644
--- a/plugins/json/setup.cfg
+++ b/plugins/json/setup.cfg
@@ -3,7 +3,7 @@ name = deephaven-plugin-json
 description = Deephaven Plugin for json
 long_description = file: README.md
 long_description_content_type = text/markdown
-version = attr:deephaven.plugin.json.__version__
+version = 0.0.2.dev0
 url = https://github.com/deephaven/deephaven-plugins
 project_urls =
     Source Code = https://github.com/deephaven/deephaven-plugins
diff --git a/plugins/json/src/deephaven/plugin/json/__init__.py b/plugins/json/src/deephaven/plugin/json/__init__.py
index 1bf18e00c..562422e8a 100644
--- a/plugins/json/src/deephaven/plugin/json/__init__.py
+++ b/plugins/json/src/deephaven/plugin/json/__init__.py
@@ -5,8 +5,6 @@
 
 from deephaven.plugin import Registration, Callback, object_type
 
-__version__ = "0.0.2.dev0"
-
 
 class Node:
     def __init__(self, object, is_ref=False, **kw) -> None:
diff --git a/plugins/plotly/setup.cfg b/plugins/plotly/setup.cfg
index 64b135cc4..c9ab3f75f 100644
--- a/plugins/plotly/setup.cfg
+++ b/plugins/plotly/setup.cfg
@@ -3,7 +3,7 @@ name = deephaven-plugin-plotly
 description = Deephaven Plugin for Plotly
 long_description = file: README.md
 long_description_content_type = text/markdown
-version = attr:deephaven.plugin.plotly.__version__
+version = 0.3.0.dev0
 url = https://github.com/deephaven/deephaven-plugins
 project_urls =
     Source Code = https://github.com/deephaven/deephaven-plugins
diff --git a/plugins/plotly/src/deephaven/plugin/plotly/__init__.py b/plugins/plotly/src/deephaven/plugin/plotly/__init__.py
index d520ce352..c4a18cf16 100644
--- a/plugins/plotly/src/deephaven/plugin/plotly/__init__.py
+++ b/plugins/plotly/src/deephaven/plugin/plotly/__init__.py
@@ -1,8 +1,6 @@
 from deephaven.plugin import Registration, Callback
 from plotly import io as pio
 
-__version__ = "0.3.0.dev0"
-
 
 def _init_theme():
     # Set the Deephaven style globally
diff --git a/tools/update_version.sh b/tools/update_version.sh
index d1fd141d2..7d5f7bd69 100755
--- a/tools/update_version.sh
+++ b/tools/update_version.sh
@@ -113,26 +113,8 @@ function update_file() {
 extra=
 [ "$dev" = true ] && extra=".dev0"
 case "$package" in
-        json)
-            update_file json/src/deephaven/plugin/json/__init__.py '__version__ = "' '"' "$extra"
-            ;;
-        matplotlib)
-            update_file matplotlib/setup.cfg 'version = ' '' "$extra"
-            ;;
-        plotly)
-            update_file plotly/src/deephaven/plugin/plotly/__init__.py '__version__ = "' '"' "$extra"
-            ;;
-        plotly-express)
-            update_file plotly-express/setup.cfg 'version = ' '' "$extra"
-            ;;
-        ui)
-            update_file ui/setup.cfg 'version = ' '' "$extra"
-            ;;
-        utilities)
-            update_file utilities/setup.cfg 'version = ' '' "$extra"
-            ;;
-        packaging)
-            update_file packaging/setup.cfg 'version = ' '' "$extra"
+        json | matplotlib | plotly | plotly-express | ui | utilities | packaging)
+            update_file "${package}/setup.cfg" 'version = ' '' "$extra"
             ;;
         auth-keycloak | dashboard-object-viewer | table-example)
             # Packages that don't have any Python to publish, just ignore


Test patch:
diff --git a/plugins/json/test/test_json_plugin.py b/plugins/json/test/test_json_plugin.py
index 8507959af..fc3791df0 100644
--- a/plugins/json/test/test_json_plugin.py
+++ b/plugins/json/test/test_json_plugin.py
@@ -1,12 +1,16 @@
 import unittest
 import importlib.resources
 import json
+import sys
 
 from deephaven.plugin.json import Encoder
 from deephaven.plugin.object_type import Exporter, Reference
 
 
 def read_text(resource: str):
+    if sys.version_info < (3, 9):
+        # Need to use legacy behaviour on Python < 3.9
+        return importlib.resources.read_text(__package__, resource)
     return importlib.resources.files(__package__).joinpath(resource).read_bytes()