Skip to content

Commit

Permalink
Support mutable objects in webviz-store (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Dec 11, 2019
1 parent 25582b1 commit b66c716
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions webviz_config/webviz_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WebvizStorage:
def __init__(self):
self._use_storage = False
self.storage_functions = set()
self.storage_function_argvalues = defaultdict(set)
self.storage_function_argvalues = defaultdict(dict)

def register_function(self, func):
"""This function is automatically called by the function
Expand Down Expand Up @@ -61,13 +61,15 @@ def register_function_arguments(self, functionarguments):
"""

for func, arglist in functionarguments:
argtuples = [
WebvizStorage._dict_to_tuples(WebvizStorage.complete_kwargs(func, args))
for args in arglist
]

undec_func = WebvizStorage._undecorate(func)
self.storage_function_argvalues[undec_func].update(argtuples)
for args in arglist:
argtuples = WebvizStorage._dict_to_tuples(
WebvizStorage.complete_kwargs(func, args)
)
if repr(argtuples) not in self.storage_function_argvalues[undec_func]:
self.storage_function_argvalues[undec_func][
repr(argtuples)
] = argtuples

def _unique_path(self, func, argtuples):
"""Encodes the argumenttuples as bytes, and then does a sha256 on that.
Expand All @@ -77,8 +79,7 @@ def _unique_path(self, func, argtuples):
`__repr__`
"""

args_as_bytes = str(argtuples).encode()
hashed_args = str(hashlib.sha256(args_as_bytes).hexdigest())
hashed_args = hashlib.sha256(repr(argtuples).encode()).hexdigest()

filename = f"{func.__module__}-{func.__name__}-{hashed_args}"

Expand Down Expand Up @@ -153,10 +154,10 @@ def build_store(self):
total_calls = sum(
len(calls) for calls in self.storage_function_argvalues.values()
)
counter = 0

counter = 0
for func in self.storage_functions:
for argtuples in self.storage_function_argvalues[func]:
for argtuples in self.storage_function_argvalues[func].values():
kwargs = dict(argtuples)

print(
Expand Down

0 comments on commit b66c716

Please sign in to comment.