Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pre commit #24

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r space2stats_api/requirements.txt
pip install pre-commit

- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)/space2stats_api" >> $GITHUB_ENV

- name: Run pre-commit
run: pre-commit run --all-files

- name: Run tests
run: pytest space2stats_api/tests
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.5
hooks:
- id: ruff
args: [--fix]
files: ^space2stats_api/

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
hooks:
- id: mypy
args: [--ignore-missing-imports]
files: ^space2stats_api/
exclude: ^space2stats/env/
16 changes: 4 additions & 12 deletions space2stats_api/app/routers/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Dict, Any, Literal, Optional
from typing import List, Dict, Any, Literal, Optional, TypeAlias
from fastapi import APIRouter

from pydantic import BaseModel, create_model
from pydantic import BaseModel
from geojson_pydantic import Feature, Polygon

from app.utils.h3_utils import generate_h3_ids, generate_h3_geometries
Expand All @@ -10,22 +10,14 @@

router = APIRouter()

AOIModel = Feature[Polygon, Dict]
AOIModel: TypeAlias = Feature[Polygon, Dict]


class SummaryRequest(BaseModel):
aoi: AOIModel
spatial_join_method: Literal["touches", "centroid", "within"]
fields: List[str]
geometry: Optional[Literal["polygon", "point"]] = False


def create_response_model(fields: List[str]):
field_definitions = {field: (Any, ...) for field in fields}
field_definitions["hex_id"] = (str, ...)
if "geometry" in fields:
field_definitions["geometry"] = (Dict[str, Any], ...)
return create_model("DynamicSummaryResponse", **field_definitions)
geometry: Optional[Literal["polygon", "point"]] = None


@router.post("/summary", response_model=List[Dict[str, Any]])
Expand Down
4 changes: 2 additions & 2 deletions space2stats_api/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Settings(BaseSettings):
DB_USER: str
DB_PASSWORD: str
DB_TABLE_NAME: str

model_config = SettingsConfigDict(env_file="../local_db.env")
model_config = SettingsConfigDict(env_file='../db.env')
zacdezgeo marked this conversation as resolved.
Show resolved Hide resolved


settings = Settings()
1 change: 0 additions & 1 deletion space2stats_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest.mock import patch

from app.main import app
from app.utils.h3_utils import generate_h3_geometries

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion space2stats_api/tests/test_h3_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from shapely.geometry import Polygon, mapping, Point
from shapely.geometry import Polygon, mapping
from app.utils.h3_utils import generate_h3_ids, generate_h3_geometries

polygon_coords = [
Expand Down
Loading