From c443b955a1db70d9461c8d69cb1808cbe4a91f13 Mon Sep 17 00:00:00 2001 From: alexPatrie Date: Sun, 26 May 2024 14:52:00 -0400 Subject: [PATCH] feat: updates to struct --- biosimulator_processes/server/__init__.py | 0 biosimulator_processes/server/main.py | 36 ---------- .../server/spec/openapi_3_1_0_generated.yaml | 69 ------------------- biosimulator_processes/server/src/__init__.py | 0 biosimulator_processes/server/src/io.py | 16 ----- .../server/src/openapi_spec.py | 36 ---------- .../{verify/core.py => verify.py} | 0 biosimulator_processes/verify/__init__.py | 0 8 files changed, 157 deletions(-) delete mode 100644 biosimulator_processes/server/__init__.py delete mode 100644 biosimulator_processes/server/main.py delete mode 100644 biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml delete mode 100644 biosimulator_processes/server/src/__init__.py delete mode 100644 biosimulator_processes/server/src/io.py delete mode 100644 biosimulator_processes/server/src/openapi_spec.py rename biosimulator_processes/{verify/core.py => verify.py} (100%) delete mode 100644 biosimulator_processes/verify/__init__.py diff --git a/biosimulator_processes/server/__init__.py b/biosimulator_processes/server/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/biosimulator_processes/server/main.py b/biosimulator_processes/server/main.py deleted file mode 100644 index a88a0af72..000000000 --- a/biosimulator_processes/server/main.py +++ /dev/null @@ -1,36 +0,0 @@ -import tempfile - -from fastapi import FastAPI, UploadFile, File -from fastapi.middleware.cors import CORSMiddleware -import uvicorn - -from biosimulator_processes.server.src.io import save_omex_archive - - -app = FastAPI(title='biosimulator-processes-server') - - -origins = [ - "http://localhost:4200", -] -app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - - -@app.post("/upload-omex") -async def upload_omex(file: UploadFile = File(...)): - contents = await file.read() - - save_dir = tempfile.mkdtemp() - archive_response = save_omex_archive(contents, save_dir) - print(archive_response['archive'].contents) - return {"filename": archive_response['source']} - - -if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml b/biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml deleted file mode 100644 index d42f8beb0..000000000 --- a/biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml +++ /dev/null @@ -1,69 +0,0 @@ -openapi: 3.1.0 -info: - title: biosimulator-processes-server - version: 0.1.0 -paths: - /upload-omex: - post: - summary: Upload Omex - operationId: upload_omex_upload_omex_post - requestBody: - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/Body_upload_omex_upload_omex_post' - required: true - responses: - '200': - description: Successful Response - content: - application/json: - schema: {} - '422': - description: Validation Error - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' -components: - schemas: - Body_upload_omex_upload_omex_post: - properties: - file: - type: string - format: binary - title: File - type: object - required: - - file - title: Body_upload_omex_upload_omex_post - HTTPValidationError: - properties: - detail: - items: - $ref: '#/components/schemas/ValidationError' - type: array - title: Detail - type: object - title: HTTPValidationError - ValidationError: - properties: - loc: - items: - anyOf: - - type: string - - type: integer - type: array - title: Location - msg: - type: string - title: Message - type: - type: string - title: Error Type - type: object - required: - - loc - - msg - - type - title: ValidationError diff --git a/biosimulator_processes/server/src/__init__.py b/biosimulator_processes/server/src/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/biosimulator_processes/server/src/io.py b/biosimulator_processes/server/src/io.py deleted file mode 100644 index 525860620..000000000 --- a/biosimulator_processes/server/src/io.py +++ /dev/null @@ -1,16 +0,0 @@ -import tempfile - -from biosimulators_utils.combine.io import CombineArchiveReader - - -def unpack_omex(archive_fp: str, save_dir: str): - return CombineArchiveReader().run(archive_fp, save_dir) - - -def save_omex_archive(contents: bytes, save_dir: str): - with tempfile.NamedTemporaryFile(delete=False, suffix='.omex') as temp_file: - temp_file.write(contents) - archive_path = temp_file.name - - return {'source': archive_path, 'archive': unpack_omex(archive_path, save_dir), 'save_dir': save_dir} - diff --git a/biosimulator_processes/server/src/openapi_spec.py b/biosimulator_processes/server/src/openapi_spec.py deleted file mode 100644 index e96de1c1c..000000000 --- a/biosimulator_processes/server/src/openapi_spec.py +++ /dev/null @@ -1,36 +0,0 @@ -import json -import os - -import yaml -from fastapi.openapi.utils import get_openapi - -from biosimulator_processes.server.main import app - - -def main(): - openapi_spec = get_openapi( - title=app.title, - version=app.version, - openapi_version=app.openapi_version, - description=app.description, - routes=app.routes, - ) - - # Convert the JSON OpenAPI spec to YAML - openapi_spec_yaml = yaml.dump(json.loads(json.dumps(openapi_spec)), sort_keys=False) - - current_directory = os.path.dirname(os.path.realpath(__file__)) - - # Write the YAML OpenAPI spec to a file in subdirectory spec - openapi_version = app.openapi_version.replace('.', '_') - spec_fp = f"{current_directory}/../spec/openapi_{openapi_version}_generated.yaml" - if os.path.exists(spec_fp): - print('Spec exists, overwriting') - os.remove(spec_fp) - - with open(spec_fp, "w") as f: - f.write(openapi_spec_yaml) - - -if __name__ == "__main__": - main() diff --git a/biosimulator_processes/verify/core.py b/biosimulator_processes/verify.py similarity index 100% rename from biosimulator_processes/verify/core.py rename to biosimulator_processes/verify.py diff --git a/biosimulator_processes/verify/__init__.py b/biosimulator_processes/verify/__init__.py deleted file mode 100644 index e69de29bb..000000000