Skip to content

Commit

Permalink
Merge pull request #78 from grillazz/77-switch-to-lifespan
Browse files Browse the repository at this point in the history
77 switch to lifespan
  • Loading branch information
grillazz authored Mar 15, 2024
2 parents 029a1c4 + fad77a6 commit 8433836
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 177 deletions.
4 changes: 3 additions & 1 deletion app/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def get_logger(self):

class RichConsoleHandler(RichHandler):
def __init__(self, width=200, style=None, **kwargs):
super().__init__(console=Console(color_system="256", width=width, style=style), **kwargs)
super().__init__(
console=Console(color_system="256", width=width, style=style), **kwargs
)
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import Depends, FastAPI

from app.config import settings
from app.config import settings
from app.logging import AppLogger
from app.redis import init_redis_pool
from app.routers import smiles_router
Expand Down
2 changes: 1 addition & 1 deletion app/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ async def init_redis_pool() -> redis.Redis:
# global_settings.redis_url.unicode_string(),
# encoding="utf-8",
# decode_responses=True,
# )
# )
9 changes: 7 additions & 2 deletions app/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ async def get_and_compare(compound: str, redis_hash: str):
mol = RDKFingerprint(MolFromSmiles(compound))

mol_hash = await main.app.state.mols_repo.get_all(redis_hash)
similarity = {smile: FingerprintSimilarity(CreateFromBitString(fp), mol) for smile, fp in mol_hash.items()}
similarity = {
smile: FingerprintSimilarity(CreateFromBitString(fp), mol)
for smile, fp in mol_hash.items()
}

return {
"number_of_smiles_to_compare": len(similarity),
"similarity": dict(sorted(similarity.items(), key=lambda item: item[1], reverse=True)),
"similarity": dict(
sorted(similarity.items(), key=lambda item: item[1], reverse=True)
),
}


Expand Down
8 changes: 6 additions & 2 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class Config:
"source": "openeye.com",
"release": "2019.06.18",
},
"value": {"sval": "CSC1=NC2=NN=C(C(=O)N2N1)[N+](=O)[O-]"},
"value": {
"sval": "CSC1=NC2=NN=C(C(=O)N2N1)[N+](=O)[O-]"
},
},
],
"count": {},
Expand All @@ -96,7 +98,9 @@ class Config:
"source": "openeye.com",
"release": "2019.06.18",
},
"value": {"sval": "CCS(=O)(=O)N1CC(C1)(CC#N)N2C=C(C=N2)C3=C4C=CNC4=NC=N3"},
"value": {
"sval": "CCS(=O)(=O)N1CC(C1)(CC#N)N2C=C(C=N2)C3=C4C=CNC4=NC=N3"
},
},
],
"count": {},
Expand Down
320 changes: 153 additions & 167 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ packages = [{include = "fastapi_redis"}]
[tool.poetry.dependencies]
python = "^3.12"
fastapi = "^0.110.0"
pydantic = {version = "2.6.1", extras = ["email"]}
pydantic-settings = "2.2.0"
pydantic = {version = "2.6.4", extras = ["email"]}
pydantic-settings = "2.2.1"
uvicorn = "^0.27.1"
redis = "^5.0.2"
wurlitzer = "^3.0.3"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
),
),
)
async def test_set_fields_on_hash(client, get_payload, response: dict, status_code: int):
async def test_set_fields_on_hash(
client, get_payload, response: dict, status_code: int
):
post_response = await client.post(
f"/smiles/add-to-hash?redis_hash={global_settings.redis_hash}",
json=get_payload,
Expand Down

0 comments on commit 8433836

Please sign in to comment.