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

Fix/backend install #185

Merged
merged 5 commits into from
Nov 15, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The set of long-running services can include:
- irv-autopkg-worker: Autopackage data processing (clipping, serialisation, etc.)
- irv-autopkg-api: Autopackage service coordination

If you're running [your own FE](https://github.com/nismod/irv-frontend/)
If you're running your own [frontend](https://github.com/nismod/irv-frontend/)
development server, or connecting to a remotely hosted database, or not using
the [autopackage API](https://github.com/nismod/irv-autopkg), you may not need
all these services.
Expand Down
10 changes: 9 additions & 1 deletion containers/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ docker-compose -f docker-compose-prod-build.yaml build backend
### Running Locally

```bash
cd containers/backend/backend
# cd to this backend app directory
cd containers/backend

# create a virtual environment (using venv or another method if you prefer)
python -m venv venv
source venv/bin/activate
pip install -e .[dev]

# run the application
uvicorn app.main:app --port 8888 --reload
```

Expand Down
10 changes: 5 additions & 5 deletions containers/backend/backend/app/internal/attribute_access.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Callable
from typing import Callable, Optional
from sqlalchemy import Column
from sqlalchemy.orm import Query
from sqlalchemy.sql import functions
Expand All @@ -16,7 +16,7 @@ def add_damages_expected_value_query(
dimensions: schemas.ExpectedDamagesDimensions,
field: str,
field_params: schemas.DataParameters,
):
) -> Query:
q = fq.join(models.Feature.damages_expected)
q = q.filter_by(rcp=dimensions.rcp, epoch=dimensions.epoch)
agg = False
Expand Down Expand Up @@ -78,7 +78,7 @@ class DataGroupConfig:
add_value_query: Callable[
[Query, schemas.DataDimensions, str, schemas.DataParameters | None], Query
]
field_parameters_schemas: dict[str, schemas.DataParameters] = None
field_parameters_schemas: Optional[dict[str, schemas.DataParameters]] = None


DATA_GROUP_CONFIGS: dict[str, DataGroupConfig] = {
Expand Down Expand Up @@ -136,8 +136,8 @@ def add_value_query(
field_group: str,
field_dimensions: schemas.DataDimensions,
field: str,
field_params: schemas.DataParameters = None,
):
field_params: Optional[schemas.DataParameters] = None,
) -> Query:
data_group_config = DATA_GROUP_CONFIGS.get(field_group)

if data_group_config is not None:
Expand Down
3 changes: 2 additions & 1 deletion containers/backend/backend/app/internal/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Singleton Helpers
"""

import logging
import traceback

from config import TILEDB_URI
Expand All @@ -14,7 +15,7 @@ def build_driver_path(database: str, tiledb_uri: str = TILEDB_URI) -> str:
return tiledb_uri + "/" + database


def handle_exception(logger, err: Exception):
def handle_exception(logger: logging.Logger, err: Exception):
"""
Handle generic exceptions
"""
Expand Down
8 changes: 4 additions & 4 deletions containers/backend/backend/app/routers/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections import OrderedDict
from sys import getsizeof
from typing import BinaryIO, List, Tuple, Union
from typing import BinaryIO, List, Optional, Tuple, Union
import json
import inspect

Expand All @@ -31,7 +31,7 @@
router = APIRouter(tags=["tiles"])


def _parse_keys(keys: str) -> List:
def _parse_keys(keys: str) -> Tuple[str, List[str]]:
"""
Parse tiles URL key str
"""
Expand All @@ -44,7 +44,7 @@ def _parse_keys(keys: str) -> List:
def _get_singleband_image(
database: str,
keys: List[str],
tile_xyz: Tuple[int, int, int] = None,
tile_xyz: Optional[Tuple[int, int, int]] = None,
options: dict = {},
) -> BinaryIO:
"""
Expand Down Expand Up @@ -92,7 +92,7 @@ def _tile_db_from_domain(domain: str) -> str:
return domain_to_db[domain]


def _source_options(source_db: str) -> List[dict]:
def _source_options(source_db: str) -> List[dict[str, str]]:
"""
Gather all URL key combinations available in the given source

Expand Down
8 changes: 4 additions & 4 deletions containers/backend/backend/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AdaptationCostBenefitRatioParameters(DataParameters):
eael_days: conint(ge=1, le=30)

@validator("eael_days")
def fix_eael_days(cls, eael_days) -> float:
def fix_eael_days(cls, eael_days: int) -> float:
"""
The data for `AdaptationCostBenefit.avoided_eael_mean` is erroneous and
should be modified in the meantime. This validator adds a fudge factor
Expand Down Expand Up @@ -175,19 +175,19 @@ class FeatureListItemOut(BaseModel, Generic[SortFieldT]):

# Tile Server metadata
class TileSourceMeta(BaseModel):
id: int = None
id: Optional[int] = None
domain: str
name: str
group: str
description: str
license: str
keys: list
keys: list[str]

model_config = ConfigDict(from_attributes=True)


class TileSourceDomains(BaseModel):
domains: List[dict]
domains: List[dict[str, str]]


class ColorMapOptions(BaseModel):
Expand Down
8 changes: 7 additions & 1 deletion containers/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ dependencies = [
"fastapi==0.109.1",
"geoalchemy2==0.12.5",
"uvicorn==0.18.3",
"psycopg2-binary==2.9.3",
"psycopg2-binary==2.9.10",
"fastapi-pagination==0.10.0",
"terracotta==0.8.3",
"sqlalchemy==1.4.41",
]

[project.optional-dependencies]
dev = ["types-sqlalchemy"]

[tool.pyright]
exclude = ["venv", ".venv"]