Skip to content

Commit

Permalink
feat(addSlices): serialize slicedata
Browse files Browse the repository at this point in the history
AddSlices wasn't serializing the slicedata it was sending up.
  • Loading branch information
wiwichips committed Sep 9, 2024
1 parent f2df7c5 commit 9529d6d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dcp/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .compute_for import compute_for_maker
from .compute_do import compute_do_maker
from .fetch_results import fetch_results_maker
from .add_slices import add_slices_maker
from .job import job_maker
from .result_handle import result_handle_maker
from .job_fs import JobFS
Expand All @@ -10,5 +11,5 @@
'ResultHandle': result_handle_maker,
}

__all__ = ['compute_for_maker', 'compute_do_maker' 'sub_classes', 'JobFS', 'fetch_results_maker']
__all__ = ['compute_for_maker', 'compute_do_maker' 'sub_classes', 'JobFS', 'fetch_results_maker', 'add_slices_maker']

36 changes: 36 additions & 0 deletions dcp/api/add_slices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
addSlices API
Author: Will Pringle <[email protected]>
Date: September 2024
"""

import pythonmonkey as pm
from .. import dry
from .. import js
from .job_serializers import default_serializers, serialize

def add_slices_maker(add_slices_js):
def is_iterable(maybe_iterable):
try:
iter(maybe_iterable)
return True
except TypeError:
return False

def add_slices(*args, serializers=default_serializers):
new_args = []

for arg in args:
if not isinstance(arg, str) and is_iterable(arg):
serialized_vals = []
for val in arg:
serialized_vals.append(serialize(val, serializers))
new_args.append(serialized_vals)
else:
new_args.append(arg)

js_val = dry.aio.blockify(add_slices_js)(*new_args)

return js_val
return add_slices
4 changes: 4 additions & 0 deletions dcp/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ def init_dcp_module(py_parent, js_module, js_name):
for prop_name, prop_ref in js_module.items():
# modify props if required
# TODO: should this be a dict of prop_name and list of modules with overridden ref?
# TODO: maybe stuff like this should be specified in one places instead of spat throughout the codebase
# TODO: tldr, should be more dry... somehow... figure out later...
if prop_name == 'fetchResults' and (js_name == 'compute' or js_name == 'job'):
setattr(module, prop_name, api.fetch_results_maker(prop_ref))
elif prop_name == 'addSlices' and js_name in ('compute', 'job'):
setattr(module, prop_name, api.add_slices_maker(prop_ref))
else:
setattr(module, prop_name, _wrap_js(prop_name, prop_ref))

Expand Down

0 comments on commit 9529d6d

Please sign in to comment.