Skip to content

Commit

Permalink
Merge pull request #46 from janash/upgrade/backend
Browse files Browse the repository at this point in the history
upgrade backend image and pydantic version
  • Loading branch information
janash authored Aug 23, 2023
2 parents 3c581c1 + f003667 commit a3eba63
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
Empty file modified backend/app/app/backend_prestart.py
100644 → 100755
Empty file.
13 changes: 7 additions & 6 deletions backend/app/app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseSettings, PostgresDsn, validator
from pydantic import PostgresDsn, validator
from pydantic_settings import SettingsConfigDict, BaseSettings

from typing import Any, Optional, Dict

Expand All @@ -12,20 +13,20 @@ class Settings(BaseSettings):
POSTGRES_DB: str
SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None

# TODO[pydantic]: We couldn't refactor the `validator`, please replace it by `field_validator` manually.
# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-validators for more information.
@validator("SQLALCHEMY_DATABASE_URI", pre=True)
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
if isinstance(v, str):
return v
return PostgresDsn.build(
scheme="postgresql",
user=values.get("POSTGRES_USER"),
username=values.get("POSTGRES_USER"),
password=values.get("POSTGRES_PASSWD"),
host=values.get("POSTGRES_SERVER"),
path=f"/{values.get('POSTGRES_DB') or ''}"
path=f"{values.get('POSTGRES_DB') or ''}"
)

class Config:
case_sensitive = True
model_config = SettingsConfigDict(case_sensitive=True)


settings = Settings()
2 changes: 1 addition & 1 deletion backend/app/app/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Models:


Base = automap_base()
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI), pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base.prepare(engine, reflect=True)

Expand Down
24 changes: 12 additions & 12 deletions backend/app/app/schemas/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
class Molecule(BaseModel):
molecule_id: int
smiles: str
molecular_weight: Optional[float]
molecular_weight: Optional[float] = None
conformers_id: List[Optional[int]]
dft_data: Optional[Dict]
xtb_data: Optional[Dict]
xtb_ni_data: Optional[Dict]
ml_data: Optional[Dict]
dft_data: Optional[Dict] = None
xtb_data: Optional[Dict] = None
xtb_ni_data: Optional[Dict] = None
ml_data: Optional[Dict] = None

class MoleculeSimple(BaseModel):
molecule_id: int
umap1: Optional[float]
umap2: Optional[float]
pat: Optional[str]
umap1: Optional[float] = None
umap2: Optional[float] = None
pat: Optional[str] = None
smiles: str

class MoleculeComponents(BaseModel):
type: Optional[str]
type: Optional[str] = None
molecule_id: int
pat: Optional[str]
pat: Optional[str] = None
smiles: str
components: Optional[list[float]]
components: Optional[list[float]] = None

class MoleculeNeighbors(MoleculeComponents):
dist: Optional[float]
dist: Optional[float] = None

class MoleculeIdentifiers(BaseModel):
smiles: str
Expand Down
12 changes: 6 additions & 6 deletions backend/app/prestart.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
#!/bin/bash

# Wait for DB to be ready
$python $(pwd)/app/backend_prestart.py
# Initialize the shell for micromamba
eval "$(micromamba shell hook --shell bash)"

# Upgrade if needed
#alembic upgrade head
# Activate the environment. If you're using a different environment name other than "base", replace it.
micromamba activate base

# Start FastAPI
# Navigate to app directory and start FastAPI using Uvicorn.
cd app
uvicorn main:app --reload --port 8080 --host 0.0.0.0
12 changes: 8 additions & 4 deletions backend/backend.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM continuumio/miniconda3
FROM mambaorg/micromamba

RUN yes | conda install -c conda-forge rdkit fastapi alembic psycopg2-binary "sqlalchemy<2.0" tenacity uvicorn curl openbabel
COPY environment.yaml* /tmp/conda-tmp/

ARG MAMBA_DOCKERFILE_ACTIVATE=1

RUN micromamba install -f /tmp/conda-tmp/environment.yaml && \
micromamba clean --all --yes

WORKDIR /app/
ADD ./app /app/
RUN pip install -e .

RUN pip install -e .
16 changes: 16 additions & 0 deletions backend/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: base
channels:
- conda-forge
- defaults
dependencies:
- python
- rdkit
- fastapi
- pydantic-settings
- alembic
- psycopg2-binary
- sqlalchemy
- tenacity
- uvicorn
- curl
- openbabel
5 changes: 0 additions & 5 deletions backend/requirements.txt

This file was deleted.

0 comments on commit a3eba63

Please sign in to comment.