Skip to content

Commit

Permalink
Merge pull request #299 from Steinbeck-Lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CS76 authored Aug 7, 2023
2 parents 8eaf58d + dc97b7f commit 95b754a
Show file tree
Hide file tree
Showing 21 changed files with 1,427 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
pip install flake8 pytest
- name: Analysing the code with pylint
run: |
flake8 --ignore E402,E501,W503 $(git ls-files '*.py')
flake8 --per-file-ignores="__init__.py:F401" --ignore E402,E501,W503 $(git ls-files '*.py') .
# - name: Run test
# run: |
# pytest -p no:warnings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
pip install flake8 pytest
- name: Analysing the code with pylint
run: |
flake8 --ignore E402,E501,W503 $(git ls-files '*.py')
flake8 --per-file-ignores="__init__.py:F401" --ignore E402,E501,W503 $(git ls-files '*.py') .
- name: Run test
run: |
python3 -m pytest -p no:warnings
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ ENV PYTHON_VERSION=3.10
ENV RDKIT_VERSION=2023.03.1
ENV OPENBABEL_VERSION=v3.1

ARG RELEASE_VERSION
ENV RELEASE_VERSION=${RELEASE_VERSION}

# Install runtime dependencies
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get update -y && \
apt-get install -y openjdk-11-jre && \
apt-get install -y curl
apt-get install -y curl && \
conda update -n base -c defaults conda

RUN wget -O surge "https://github.com/StructureGenerator/surge/releases/download/v1.0/surge-linux-v1.0"
RUN chmod +x surge
Expand Down
63 changes: 47 additions & 16 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
from fastapi import FastAPI
from fastapi import FastAPI, status
from fastapi.responses import RedirectResponse
from fastapi_versioning import VersionedFastAPI

from .routers import chem, converters, depict, tools, ocsr
from fastapi.middleware.cors import CORSMiddleware

from prometheus_fastapi_instrumentator import Instrumentator
from app.schemas import HealthCheck

app = FastAPI(
title="Cheminformatics Python Microservice",
title="Cheminformatics Microservice",
description="This set of essential and valuable microservices is designed to be accessed via API calls to support cheminformatics. Generally, it is designed to work with SMILES-based inputs and could be used to translate between different machine-readable representations, get Natural Product (NP) likeliness scores, visualize chemical structures, and generate descriptors. In addition, the microservices also host an instance of STOUT and another instance of DECIMER (two deep learning models for IUPAC name generation and optical chemical structure recognition, respectively).",
terms_of_service="https://steinbeck-lab.github.io/cheminformatics-python-microservice",
contact={
Expand All @@ -23,16 +24,6 @@
},
)

origins = ["*"]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(chem.router)
app.include_router(converters.router)
app.include_router(depict.router)
Expand All @@ -54,14 +45,54 @@
"name": "CC BY 4.0",
"url": "https://creativecommons.org/licenses/by/4.0/",
},
version=os.getenv('RELEASE_VERSION', '1.0')
version=os.getenv("RELEASE_VERSION", "1.0"),
)

Instrumentator().instrument(app).expose(app)

origins = ["*"]


@app.middleware("http")
async def add_cors_headers(request, call_next):
response = await call_next(request)
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Credentials"] = "true"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization"
return response


app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


@app.get("/", include_in_schema=False)
async def root():
return RedirectResponse(
url="https://steinbeck-lab.github.io/cheminformatics-python-microservice"
)
return RedirectResponse(url=os.getenv("HOMEPAGE_URL", "/latest/docs"))


@app.get(
"/health",
tags=["healthcheck"],
summary="Perform a Health Check",
response_description="Return HTTP Status Code 200 (OK)",
status_code=status.HTTP_200_OK,
response_model=HealthCheck,
)
def get_health() -> HealthCheck:
"""
## Perform a Health Check
Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker
to ensure a robust container orchestration and management is in place. Other
services which rely on proper functioning of the API service will not deploy if this
endpoint returns any other HTTP status code except 200 (OK).
Returns:
HealthCheck: Returns a JSON response with the health status
"""
return HealthCheck(status="OK")
Loading

0 comments on commit 95b754a

Please sign in to comment.