Skip to content

Commit 575059b

Browse files
committed
Fix: merge conflicts issue 130
2 parents be40db2 + 70ae1c1 commit 575059b

24 files changed

Lines changed: 1518 additions & 53 deletions

.github/workflows/pytest_unit.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,12 @@ jobs:
1313
with:
1414
python-version: '3.13'
1515

16-
- uses: actions/cache@v5
17-
id: cache
16+
- uses: astral-sh/setup-uv@v6
1817
with:
19-
path: ~/.cache/pip
20-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
21-
restore-keys: |
22-
${{ runner.os }}-pip-
18+
enable-cache: true
2319

2420
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
python -m venv venv
28-
source ./venv/bin/activate
29-
pip install ".[test]"
21+
run: uv sync --extra test --locked
3022

3123
- name: Run unit tests
32-
run: PYTHONPATH=src ./venv/bin/python -m pytest ./tests/unit -v
24+
run: uv run pytest ./tests/unit -v

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ wheels
1616

1717
.venv
1818
.DS_Store
19+
.env

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ dependencies = [
1212
"asyncpg==0.31.0",
1313
"alembic==1.18.4",
1414
"google-api-python-client==2.194.0",
15-
1615
# minor
1716
"xmltodict==0.13.0",
1817
"httpx==0.28.1",
18+
"pydantic-settings==2.14.1",
19+
"gtfs-realtime-bindings==2.0.0",
20+
"pandas==3.0.3",
1921
]
2022

2123
[project.optional-dependencies]
2224
dev = [
2325
"ruff==0.15.12", # linting and formatter
24-
"pre-commit"
26+
"pre-commit",
2527
]
2628

2729
test = [
2830
"pytest", # test framework
2931
"pytest-asyncio",
30-
"httpx",
3132
]
3233

3334
[project.urls]

src/alembic/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import honorary.tables
1515
import nominees.tables
1616
import officers.tables
17+
import translink.tables
1718
from alembic import context
1819

1920
# this is the Alembic Config object, which provides
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Merge events and translink branches
2+
3+
Revision ID: 401b254a02a5
4+
Revises: 42f855bec532, c1a70c8cfd64
5+
Create Date: 2026-06-07 12:25:14.294686
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '401b254a02a5'
16+
down_revision: Union[str, None] = ('42f855bec532', 'c1a70c8cfd64')
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
pass
23+
24+
25+
def downgrade() -> None:
26+
pass
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Create TransLink static schedule
2+
3+
Revision ID: c1a70c8cfd64
4+
Revises: 0a2c458d1ddd
5+
Create Date: 2026-05-17 16:17:26.176355
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
from sqlalchemy.dialects import postgresql
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = 'c1a70c8cfd64'
16+
down_revision: Union[str, None] = '0a2c458d1ddd'
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table('translink_static_schedule',
24+
sa.Column('id', sa.Integer(), nullable=False),
25+
sa.Column('date_fetched', sa.Date(), nullable=False),
26+
sa.Column('schedule', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
27+
sa.PrimaryKeyConstraint('id', name=op.f('pk_translink_static_schedule'))
28+
)
29+
# ### end Alembic commands ###
30+
31+
32+
def downgrade() -> None:
33+
# ### commands auto generated by Alembic - please adjust! ###
34+
op.drop_table('translink_static_schedule')
35+
# ### end Alembic commands ###
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Create TransLink realtime cache
2+
3+
Revision ID: f0c99d0db277
4+
Revises: 401b254a02a5
5+
Create Date: 2026-06-26 16:54:33.26523
6+
7+
"""
8+
9+
from collections.abc import Sequence
10+
11+
import sqlalchemy as sa
12+
from alembic import op
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = "f0c99d0db277"
16+
down_revision: str | None = "401b254a02a5"
17+
branch_labels: str | Sequence[str] | None = None
18+
depends_on: str | Sequence[str] | None = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table(
24+
"translink_realtime_cache",
25+
sa.Column("id", sa.Integer(), nullable=False),
26+
sa.Column("fetched_at", sa.DateTime(timezone=True), nullable=False),
27+
sa.Column("response_bytes", sa.LargeBinary(), nullable=False),
28+
sa.PrimaryKeyConstraint("id", name=op.f("pk_translink_realtime_cache")),
29+
)
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade() -> None:
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
op.drop_table("translink_realtime_cache")
36+
# ### end Alembic commands ###

src/auth/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import urllib.parse
55

6-
import httpx
76
import xmltodict
87
from fastapi import APIRouter, BackgroundTasks, HTTPException, Request, Response
98
from fastapi.responses import JSONResponse, RedirectResponse

src/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
2+
3+
4+
class Settings(BaseSettings):
5+
model_config = SettingsConfigDict(env_file=".env")
6+
7+
translink_api_key: str | None = None
8+
9+
10+
settings = Settings()

src/database.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from typing import Annotated, Any
66

77
import asyncpg
8-
import httpx
9-
from fastapi import Depends, FastAPI
8+
from fastapi import Depends
109
from sqlalchemy import MetaData
1110
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession, async_sessionmaker, create_async_engine
1211
from sqlalchemy.orm import DeclarativeBase
@@ -100,26 +99,14 @@ async def session(self) -> AsyncGenerator[AsyncSession]:
10099
def setup_database():
101100
global sessionmanager
102101

102+
db_url = SQLALCHEMY_TEST_DATABASE_URL if os.environ.get("ENV") == "test" else SQLALCHEMY_DATABASE_URL
103103
# TODO: where is sys.stdout piped to? I want all these to go to a specific logs folder
104104
sessionmanager = DatabaseSessionManager(
105-
SQLALCHEMY_TEST_DATABASE_URL if os.environ.get("LOCAL") else SQLALCHEMY_DATABASE_URL,
105+
db_url,
106106
{"echo": True},
107107
)
108108

109109

110-
@contextlib.asynccontextmanager
111-
async def lifespan(app: FastAPI):
112-
"""
113-
Handles startup and shutdown events, see https://fastapi.tiangolo.com/advanced/events/
114-
"""
115-
app.state.http_client = httpx.AsyncClient()
116-
yield
117-
await app.state.http_client.aclose()
118-
if sessionmanager._engine is not None:
119-
# Close the DB connection
120-
await sessionmanager.close()
121-
122-
123110
async def get_db_session():
124111
async with sessionmanager.session() as session:
125112
yield session

0 commit comments

Comments
 (0)