Skip to content

Commit

Permalink
Make plugin id semi-deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Aug 5, 2020
1 parent c7967cf commit 66e8a6c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions webviz_config/_plugin_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import abc
import base64
import zipfile
from uuid import uuid4
from typing import List, Optional, Type, Union

import bleach
Expand All @@ -26,6 +25,13 @@ def layout(self):
```
"""

# Class variable used for counting number of plugin instaces, which
# is again used for giving semi-deterministic plugin IDs. E.g. runs
# coming from the same configuration file or webviz app will have
# the same ID for the different plugin instances, which makes it possible
# for plugins to utilize the Dash persistence system.
_number_instances = 0

# This is the default set of buttons to show in the rendered plugin
# toolbar. If the list is empty, the subclass plugin layout will be
# used directly, without any visual encapsulation layout from this
Expand Down Expand Up @@ -60,7 +66,10 @@ def __init__(self) -> None:
in its own `__init__` function in order to also run the parent `__init__`.
"""

self._plugin_uuid = uuid4()
WebvizPluginABC._number_instances += 1
self._plugin_id = (
f"{self.__class__.__name__}-{WebvizPluginABC._number_instances}"
)

def uuid(self, element: str) -> str:
"""Typically used to get a unique ID for some given element/component in
Expand All @@ -77,7 +86,7 @@ def uuid(self, element: str) -> str:
file changes in a non-portable setting).
"""

return f"{element}-{self._plugin_uuid}"
return f"{element}-{self._plugin_id}"

@property
@abc.abstractmethod
Expand All @@ -89,7 +98,7 @@ def layout(self) -> Union[str, Type[Component]]:

@property
def _plugin_wrapper_id(self) -> str:
return f"plugin-wrapper-{self._plugin_uuid}"
return f"plugin-wrapper-{self._plugin_id}"

@property
def plugin_data_output(self) -> Output:
Expand Down

0 comments on commit 66e8a6c

Please sign in to comment.