Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 1c90510

Browse files
author
Phil Varner
committed
Merge branch 'main' into 87_order_parameters
2 parents 8f3a996 + e1f5d79 commit 1c90510

File tree

20 files changed

+175
-77
lines changed

20 files changed

+175
-77
lines changed

.github/actions/pre-commit/action.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**Related Issue(s):**
2+
3+
- #
4+
5+
**Proposed Changes:**
6+
7+
1.
8+
2.
9+
10+
**PR Checklist:**
11+
12+
- [ ] I have added my changes to the [CHANGELOG](https://github.com/Element84/filmdrop-ui/blob/main/CHANGELOG.md) **or** a CHANGELOG entry is not required.

.github/workflows/pr.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,24 @@ on:
55
branches: ["main"]
66

77
jobs:
8-
lint:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v4
12-
- run: pipx install pre-commit
13-
- name: Run commit checks
14-
uses: ./.github/actions/pre-commit
15-
168
test:
179
runs-on: ubuntu-latest
1810
strategy:
1911
matrix:
2012
python-version: ["3.12"]
21-
2213
steps:
2314
- uses: actions/checkout@v4
2415
- run: pipx install poetry==1.7.1
2516
- uses: actions/setup-python@v5
2617
with:
27-
python-version: "3.12"
18+
python-version: ${{ matrix.python-version }}
2819
cache: poetry
2920
- name: Install dependencies
3021
run: poetry install --with=dev
22+
- name: Lint code
23+
if: ${{ matrix.python-version == 3.12 }}
24+
run: |
25+
python -m pip install pre-commit
26+
pre-commit run --all-files
3127
- name: Run tests
3228
run: poetry run nox

.pre-commit-config.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-merge-conflict
66
- id: end-of-file-fixer
@@ -10,8 +10,15 @@ repos:
1010
- id: trailing-whitespace
1111
- id: no-commit-to-branch
1212
- repo: https://github.com/charliermarsh/ruff-pre-commit
13-
rev: "v0.3.7"
13+
rev: v0.7.3
1414
hooks:
1515
- id: ruff
1616
args: [--fix, --exit-non-zero-on-fix]
1717
- id: ruff-format
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v1.13.0
20+
hooks:
21+
- id: mypy
22+
files: ".*\\.py$"
23+
additional_dependencies:
24+
- types-pyRFC3339~=1.1.1

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Conformance endpoint `/conformance` and root body `conformsTo` attribute.
13+
14+
### Changed
15+
16+
none
17+
18+
### Deprecated
19+
20+
none
21+
22+
### Removed
23+
24+
none
25+
26+
### Fixed
27+
28+
none
29+
30+
### Security
31+
32+
none
33+
1034
## [v0.1.0] - 2024-10-23
1135

1236
Initial release

bin/server.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
from uuid import uuid4
22

33
from fastapi import FastAPI, Request
4+
45
from stapi_fastapi.backends.product_backend import ProductBackend
6+
from stapi_fastapi.backends.root_backend import RootBackend
57
from stapi_fastapi.exceptions import NotFoundException
8+
from stapi_fastapi.models.conformance import CORE
69
from stapi_fastapi.models.opportunity import (
710
Opportunity,
811
OpportunityProperties,
912
OpportunityRequest,
1013
)
11-
from stapi_fastapi.models.order import Order, OrderParameters, OrderRequest
14+
from stapi_fastapi.models.order import (
15+
Order,
16+
OrderCollection,
17+
OrderParameters,
18+
OrderRequest,
19+
)
1220
from stapi_fastapi.models.product import (
1321
Product,
1422
Provider,
@@ -22,15 +30,15 @@ class MockOrderDB(dict[int | str, Order]):
2230
pass
2331

2432

25-
class MockRootBackend:
33+
class MockRootBackend(RootBackend):
2634
def __init__(self, orders: MockOrderDB) -> None:
2735
self._orders: MockOrderDB = orders
2836

29-
async def get_orders(self, request: Request) -> list[Order]:
37+
async def get_orders(self, request: Request) -> OrderCollection:
3038
"""
3139
Show all orders.
3240
"""
33-
return list(self._orders.values())
41+
return OrderCollection(features=list(self._orders.values()))
3442

3543
async def get_order(self, order_id: str, request: Request) -> Order:
3644
"""
@@ -115,7 +123,7 @@ class TestOrderParameters(OrderParameters):
115123
backend=product_backend,
116124
)
117125

118-
root_router = RootRouter(root_backend)
126+
root_router = RootRouter(root_backend, conformances=[CORE])
119127
root_router.add_product(product)
120128
app: FastAPI = FastAPI()
121129
app.include_router(root_router, prefix="")

src/stapi_fastapi/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

33
from fastapi import HTTPException, status
44

@@ -13,5 +13,5 @@ def __init__(self, detail: Any) -> None:
1313

1414

1515
class NotFoundException(StapiException):
16-
def __init__(self, detail: Any) -> None:
16+
def __init__(self, detail: Optional[Any] = None) -> None:
1717
super().__init__(status.HTTP_404_NOT_FOUND, detail)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pydantic import BaseModel, Field
2+
3+
CORE = "https://stapi.example.com/v0.1.0/core"
4+
OPPORTUNITIES = "https://stapi.example.com/v0.1.0/opportunities"
5+
6+
7+
class Conformance(BaseModel):
8+
conforms_to: list[str] = Field(
9+
default_factory=list, serialization_alias="conformsTo"
10+
)

src/stapi_fastapi/models/order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class OrderParameters(BaseModel):
1414
model_config = ConfigDict(extra="allow")
1515

1616

17-
ORP = TypeVar("P", bound=OrderParameters)
18-
OPP = TypeVar("O", bound=OpportunityProperties)
17+
ORP = TypeVar("ORP", bound=OrderParameters)
18+
OPP = TypeVar("OPP", bound=OpportunityProperties)
1919

2020

2121
class OrderRequest(BaseModel, Generic[ORP]):
@@ -45,7 +45,7 @@ class OrderProperties(BaseModel, Generic[OPP, ORP]):
4545
class Order(Feature[Geometry, OrderProperties]):
4646
# We need to enforce that orders have an id defined, as that is required to
4747
# retrieve them via the API
48-
id: StrictInt | StrictStr # type: ignore
48+
id: StrictInt | StrictStr
4949
type: Literal["Feature"] = "Feature"
5050
links: list[Link] = Field(default_factory=list)
5151

src/stapi_fastapi/models/root.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from pydantic import BaseModel
1+
from pydantic import BaseModel, Field
22

33
from stapi_fastapi.models.shared import Link
44

55

66
class RootResponse(BaseModel):
7-
links: list[Link]
7+
id: str
8+
conformsTo: list[str] = Field(default_factory=list)
9+
title: str = ""
10+
description: str = ""
11+
links: list[Link] = Field(default_factory=list)

0 commit comments

Comments
 (0)