Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json encoding to fstring autocompletion #686

Merged
merged 6 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pyflask/apis/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def post(self):


@neuroconv_api.route("/locate")
class Locate(Resource):
class LocateData(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
Expand All @@ -79,7 +79,7 @@ def post(self):


@neuroconv_api.route("/locate/autocomplete")
class Locate(Resource):
class AutoCompleteFormatString(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
Expand All @@ -93,12 +93,13 @@ def post(self):
class Metadata(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
# try:
return get_metadata_schema(neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces"))

# except Exception as exception:
# if notBadRequestException(exception):
# neuroconv_api.abort(500, str(exception))
try:
return get_metadata_schema(
neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces")
)
except Exception as exception:
if notBadRequestException(exception):
neuroconv_api.abort(500, str(exception))


@neuroconv_api.route("/convert")
Expand Down
6 changes: 4 additions & 2 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def coerce_schema_compliance_recursive(obj, schema):

def autocomplete_format_string(info: dict) -> str:
from neuroconv.tools.path_expansion import construct_path_template
from neuroconv.utils.json_schema import NWBMetaDataEncoder

base_directory = info["base_directory"]
filesystem_entry_path = info["path"]
Expand Down Expand Up @@ -162,12 +163,13 @@ def autocomplete_format_string(info: dict) -> str:

all_matched = locate_data(dict(autocomplete=to_locate_info))

return dict(matched=all_matched, format_string=format_string)
return json.loads(json.dumps(obj=dict(matched=all_matched, format_string=format_string), cls=NWBMetaDataEncoder))


def locate_data(info: dict) -> dict:
"""Locate data from the specifies directories using fstrings."""
from neuroconv.tools import LocalPathExpander
from neuroconv.utils.json_schema import NWBMetaDataEncoder

expander = LocalPathExpander()

Expand All @@ -191,7 +193,7 @@ def locate_data(info: dict) -> dict:

organized_output[subject_id][session_id] = item

return organized_output
return json.loads(json.dumps(obj=organized_output, cls=NWBMetaDataEncoder))


def module_to_dict(my_module):
Expand Down
Loading