Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ dev = [
"pytest>=8.0",
"pytest-cov>=4.0",
"ruff>=0.4",
"ty>=0.0.59",
"import-linter>=2.0",
]
notebooks = [
"jupyterlab>=4.0",
"ipykernel>=6.0",
"pandas>=2.0",
"matplotlib>=3.8",
"seaborn>=0.13",
]

[project.scripts]
pbs-client = "pbs_client.cli:main"
Expand Down
5 changes: 3 additions & 2 deletions src/pbs_client/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def fields(self) -> tuple[str, ...]:

@property
def primary_key(self) -> tuple[str, ...]:
return tuple(column.name for column in self.model.__table__.primary_key.columns)
return tuple(column.name for column in self.model.__table__.primary_key)


RESOURCE_SPECS = (
Expand Down Expand Up @@ -101,6 +101,8 @@ def primary_key(self) -> tuple[str, ...]:
ResourceSpec("Fee", "/fees", Fee),
ResourceSpec("Indication", "/indications", Indication),
ResourceSpec("Item", "/items", Item),
# Opt-in only: excluded from SYNC_ORDER below. Its own fields and every
# nested array duplicate Item plus 8 already-synced relationship tables
ResourceSpec("ItemOverview", "/item-overview", ItemOverview),
ResourceSpec("ItemAmt", "/amt-items", ItemAmt),
ResourceSpec("ItemAtcRltd", "/item-atc-relationships", ItemAtcRltd),
Expand Down Expand Up @@ -166,7 +168,6 @@ def primary_key(self) -> tuple[str, ...]:
"Fee",
"RestrictionText",
"Item",
"ItemOverview",
"ContainerWholesalerRltd",
"CriteriaParameterRltd",
"ExPrepSfpRltd",
Expand Down
2 changes: 1 addition & 1 deletion src/pbs_client/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class Sleeper(Protocol):
def __call__(self, seconds: float) -> None: ...
def __call__(self, seconds: float, /) -> None: ...


@dataclass(frozen=True, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion src/pbs_client/sync/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def upsert_records(session: Session, model: type[Base], records: Iterable[dict[s
fields = tuple(
column.name for column in model.__table__.columns if column.name != "raw_payload"
)
primary_key = tuple(column.name for column in model.__table__.primary_key.columns)
primary_key = tuple(column.name for column in model.__table__.primary_key)
written = 0
for record in records:
if not isinstance(record, dict):
Expand Down
4 changes: 3 additions & 1 deletion src/pbs_client/toolkit/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def resolve_schedule(session: Session, as_of: date | datetime | str) -> Schedule
target = _as_date(as_of)
schedules = session.scalars(select(Schedule)).all()
eligible = [schedule for schedule in schedules if _as_date(schedule.effective_date) <= target]
return max(eligible, key=lambda schedule: _as_date(schedule.effective_date), default=None)
if not eligible:
return None
return max(eligible, key=lambda schedule: _as_date(schedule.effective_date))


def find_items(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

def test_all_api_resources_have_models_and_keys():
assert len(RESOURCE_SPECS) == 35
assert set(SYNC_ORDER) == set(MODEL_BY_NAME)
# ItemOverview is opt-in only (see schema.py): it duplicates Item plus 8
# already-synced relationship tables
assert set(MODEL_BY_NAME) - set(SYNC_ORDER) == {"ItemOverview"}
assert all(spec.primary_key for spec in RESOURCE_SPECS)
assert all(set(spec.primary_key) <= set(spec.fields) for spec in RESOURCE_SPECS)

Expand Down
2,142 changes: 2,120 additions & 22 deletions uv.lock

Large diffs are not rendered by default.

Loading