Skip to content

Commit

Permalink
swap naming to 'namespace'
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed May 27, 2024
1 parent a3f1e71 commit c9d2968
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 124 deletions.
6 changes: 0 additions & 6 deletions src/pyflask/apis/__init__.py

This file was deleted.

30 changes: 14 additions & 16 deletions src/pyflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
multiprocessing.freeze_support()


from apis import (
dandi_api,
data_api,
neuroconv_api,
neurosift_api,
startup_api,
system_api,
)
from flask import Flask, request, send_file, send_from_directory
from flask_cors import CORS
from flask_restx import Api, Resource
Expand All @@ -34,6 +26,14 @@
is_packaged,
resource_path,
)
from namespaces import (
dandi_namespace,
data_namespace,
neuroconv_namespace,
neurosift_namespace,
startup_namespace,
system_namespace,
)

app = Flask(__name__)

Expand All @@ -57,16 +57,14 @@
title="NWB GUIDE API",
description="The REST API for the NWB GUIDE provided by the Python Flask Server.",
)
api.add_namespace(startup_api)
api.add_namespace(neuroconv_api)
api.add_namespace(data_api)
api.add_namespace(system_api)
api.add_namespace(dandi_api)
api.add_namespace(neurosift_api)
api.add_namespace(startup_namespace)
api.add_namespace(neuroconv_namespace)
api.add_namespace(data_namespace)
api.add_namespace(system_namespace)
api.add_namespace(dandi_namespace)
api.add_namespace(neurosift_namespace)
api.init_app(app)

registered = {}


@api.route("/log")
class Log(Resource):
Expand Down
6 changes: 6 additions & 0 deletions src/pyflask/namespaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .dandi import dandi_namespace
from .data import data_namespace
from .neuroconv import neuroconv_namespace
from .neurosift import neurosift_namespace
from .startup import startup_namespace
from .system import system_namespace
6 changes: 3 additions & 3 deletions src/pyflask/apis/dandi.py → src/pyflask/namespaces/dandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import flask_restx

dandi_api = flask_restx.Namespace(
dandi_namespace = flask_restx.Namespace(
name="dandi", description="Request various static listings from the DANDI Python API."
)


@dandi_api.route(rule="/get-recommended-species")
@dandi_namespace.route(rule="/get-recommended-species")
class SupportedSpecies(flask_restx.Resource):

@dandi_api.doc(
@dandi_namespace.doc(
description="Request the list of currently supported species (by Latin Binomial name) for DANDI. Note that any "
"explicit NCBI taxonomy link is also supported.",
)
Expand Down
20 changes: 10 additions & 10 deletions src/pyflask/apis/data.py → src/pyflask/namespaces/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from flask_restx import Namespace, Resource, reqparse
from manageNeuroconv import generate_dataset, generate_test_data

data_api = Namespace("data", description="API route for dataset generation in the NWB GUIDE.")
data_namespace = Namespace("data", description="API route for dataset generation in the NWB GUIDE.")


@data_api.errorhandler(Exception)
@data_namespace.errorhandler(Exception)
def exception_handler(error):
exceptiondata = traceback.format_exception(type(error), error, error.__traceback__)
return {"message": exceptiondata[-1], "traceback": "".join(exceptiondata)}
Expand All @@ -18,16 +18,16 @@ def exception_handler(error):
generate_test_data_parser.add_argument("output_path", type=str, required=True)


@data_api.route("/generate")
@data_api.expect(generate_test_data_parser)
@data_namespace.route("/generate")
@data_namespace.expect(generate_test_data_parser)
class GeneratetestData(Resource):
@data_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
@data_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
arguments = generate_test_data_parser.parse_args()
generate_test_data(output_path=arguments["output_path"])
except Exception as exception:
data_api.abort(500, str(exception))
data_namespace.abort(500, str(exception))
raise exception


Expand All @@ -36,14 +36,14 @@ def post(self):
generate_test_dataset_parser.add_argument("input_path", type=str, required=True)


@data_api.route("/generate/dataset")
@data_api.expect(generate_test_data_parser)
@data_namespace.route("/generate/dataset")
@data_namespace.expect(generate_test_data_parser)
class GenerateDataset(Resource):
@data_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
@data_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
arguments = generate_test_dataset_parser.parse_args()
return generate_dataset(input_path=arguments["input_path"], output_path=arguments["output_path"])

except Exception as exception:
data_api.abort(500, str(exception))
data_namespace.abort(500, str(exception))
Loading

0 comments on commit c9d2968

Please sign in to comment.