Skip to content

Commit 17955c4

Browse files
Merge branch 'main' of github.com:CSSS/csss-site-backend into fix_132_nominee-fk-conflict
2 parents 47947ea + 324a299 commit 17955c4

6 files changed

Lines changed: 117 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/astral-sh/ruff-pre-commit
99
# Ruff version
10-
rev: v0.4.4
10+
rev: v0.15.12
1111
hooks:
1212
# Run linter
13-
- id: ruff
13+
- id: ruff-check
1414
args: [ --fix ]
1515
# Run formatter
1616
- id: ruff-format

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ If you're planning to read through the source code, please check out this projec
2020
4. Install developer dependencies
2121
```bash
2222
# Install main dependencies
23-
pip install . # or: uv pip install .
23+
pip install . # or: uv sync
2424

2525
# Install with dev dependencies
26-
pip install ".[dev]" # or: uv pip install ".[dev]"
26+
pip install ".[dev]" # or: uv sync --extra dev
2727

2828
# Install with test dependencies
29-
pip install ".[test]" # or: uv pip install ".[test]"
29+
pip install ".[test]" # or: uv sync --extra test
3030

3131
# Install with all dependencies
32-
pip install ".[dev, test]" # or: uv pip install ".[dev, test]"
32+
pip install ".[dev, test]" # or: uv sync --all-extras
3333
```
3434

3535
5. Follow the database setup instructions on the [wiki](https://github.com/CSSS/csss-site-backend/wiki/1.-Local-Setup#database-setup). The recommended way is to do it through Docker, but both should work.
3636
6. You will need to set the following environment variables
3737
```bash
38-
export DB_PORT=5444 # The port your database is listening at
38+
export DB_PORT=5444 # If you're using Docker
3939
export LOCAL=true # Should be true if you're running this locally
4040
```
4141

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies = [
2121
[project.optional-dependencies]
2222
dev = [
2323
"ruff==0.15.12", # linting and formatter
24+
"pre-commit"
2425
]
2526

2627
test = [

src/auth/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ async def login_user(
5454
service_url = body.service
5555
service = urllib.parse.quote(service_url)
5656
service_validate_url = f"https://cas.sfu.ca/cas/serviceValidate?service={service}&ticket={body.ticket}"
57-
async with httpx.AsyncClient() as client:
58-
response = await client.get(service_validate_url)
57+
client = request.app.state.http_client
58+
response = await client.get(service_validate_url)
5959
cas_response = xmltodict.parse(response.text)
6060

6161
if "cas:authenticationFailure" in cas_response["cas:serviceResponse"]:

src/database.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import asyncio
22
import contextlib
33
import os
4-
from collections.abc import AsyncIterator
4+
from collections.abc import AsyncGenerator
55
from typing import Annotated, Any
66

77
import asyncpg
88
import httpx
9-
import sqlalchemy
109
from fastapi import Depends, FastAPI
1110
from sqlalchemy import MetaData
12-
from sqlalchemy.ext.asyncio import (
13-
AsyncConnection,
14-
AsyncSession,
15-
)
11+
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession, async_sessionmaker, create_async_engine
1612
from sqlalchemy.orm import DeclarativeBase
1713

1814
convention = {
@@ -31,8 +27,8 @@ class Base(DeclarativeBase):
3127
# from: https://medium.com/@tclaitken/setting-up-a-fastapi-app-with-async-sqlalchemy-2-0-pydantic-v2-e6c540be4308
3228
class DatabaseSessionManager:
3329
def __init__(self, db_url: str, engine_kwargs: dict[str, Any], check_db=True):
34-
self._engine = sqlalchemy.ext.asyncio.create_async_engine(db_url, **engine_kwargs)
35-
self._sessionmaker = sqlalchemy.ext.asyncio.async_sessionmaker(autocommit=False, bind=self._engine)
30+
self._engine = create_async_engine(db_url, **engine_kwargs)
31+
self._sessionmaker = async_sessionmaker(autocommit=False, bind=self._engine)
3632

3733
if check_db:
3834
# check if the database exists by making a test connection
@@ -63,7 +59,7 @@ async def close(self):
6359
self._sessionmaker = None
6460

6561
@contextlib.asynccontextmanager
66-
async def connect(self) -> AsyncIterator[AsyncConnection]:
62+
async def connect(self) -> AsyncGenerator[AsyncConnection]:
6763
if self._engine is None:
6864
raise Exception("DatabaseSessionManager is not initialized")
6965

@@ -75,7 +71,7 @@ async def connect(self) -> AsyncIterator[AsyncConnection]:
7571
raise
7672

7773
@contextlib.asynccontextmanager
78-
async def session(self) -> AsyncIterator[AsyncSession]:
74+
async def session(self) -> AsyncGenerator[AsyncSession]:
7975
if self._sessionmaker is None:
8076
raise Exception("DatabaseSessionManager is not initialized")
8177

uv.lock

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)