diff --git a/openflexure_microscope/common/labthings/plugins.py b/openflexure_microscope/common/labthings/plugins.py index bfb4d857..a7891379 100644 --- a/openflexure_microscope/common/labthings/plugins.py +++ b/openflexure_microscope/common/labthings/plugins.py @@ -6,7 +6,11 @@ from importlib import util import sys from openflexure_microscope.config import USER_CONFIG_DIR -from openflexure_microscope.utilities import camel_to_snake, camel_to_spine +from openflexure_microscope.utilities import ( + camel_to_snake, + camel_to_spine, + snake_to_spine, +) class BasePlugin: @@ -96,7 +100,7 @@ class BasePlugin: @property def _name_uri_safe(self): - return camel_to_spine(self._name_python_safe) + return snake_to_spine(self._name_python_safe) def find_plugins(plugin_path, module_name="plugins"): diff --git a/openflexure_microscope/utilities.py b/openflexure_microscope/utilities.py index 20a543ad..7fec2e36 100644 --- a/openflexure_microscope/utilities.py +++ b/openflexure_microscope/utilities.py @@ -12,12 +12,14 @@ def deserialise_array_b64(b64_string, dtype, shape): flat_arr = np.fromstring(base64.b64decode(b64_string), dtype) return flat_arr.reshape(shape) + def serialise_array_b64(npy_arr): - b64_string = base64.b64encode(npy_arr).decode('ascii') + b64_string = base64.b64encode(npy_arr).decode("ascii") dtype = str(npy_arr.dtype) shape = npy_arr.shape return b64_string, dtype, shape + def get_by_path(root, items): """Access a nested object in root by item sequence.""" return reduce(operator.getitem, items, root) @@ -69,6 +71,10 @@ def camel_to_spine(name): return re.sub("([a-z0-9])([A-Z])", r"\1-\2", s1).lower() +def snake_to_spine(name): + return name.replace("_", "-") + + @contextmanager def set_properties(obj, **kwargs): """A context manager to set, then reset, certain properties of an object.