-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eddf47
commit 02f04b6
Showing
11 changed files
with
345 additions
and
907 deletions.
There are no files selected for viewing
Binary file modified
BIN
-6 Bytes
(100%)
biosimulator_processes/processes/__pycache__/copasi_process.cpython-310.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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) |
69 changes: 69 additions & 0 deletions
69
biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.