Skip to content

Commit

Permalink
make mypy pass, remove unnecessary action install
Browse files Browse the repository at this point in the history
  • Loading branch information
atvaccaro committed Aug 2, 2023
1 parent 1fc82dd commit 48f0ecf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-calitp-map-utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
working-directory: apps/maps
steps:
- uses: actions/checkout@v3
- run: sudo apt-get install -y libgraphviz-dev graphviz-dev
- uses: actions/setup-python@v4
with:
python-version: '3.9'
Expand Down
37 changes: 26 additions & 11 deletions apps/maps/calitp_map_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import json
import os
from enum import Enum
from typing import Any, Dict, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union

import gcsfs
import gcsfs # type: ignore[import]
import requests
import typer
from furl import furl
from furl import furl # type: ignore[import]
from geojson_pydantic import Feature, FeatureCollection, MultiPolygon, Point, Polygon
from geojson_pydantic.geometries import Geometry
from geojson_pydantic.types import Position
Expand All @@ -32,16 +32,23 @@ class Tooltip(BaseModel):
style: Optional[Dict[str, Any]]


# https://github.com/pydantic/pydantic/discussions/5528#discussioncomment-5663312
if TYPE_CHECKING:
Color = Optional[list[int]]
else:
# we add alpha in the JS if only 3 colors are passed
Color = Optional[conlist(int, min_items=3, max_items=4)]


class Speedmap(BaseModel):
stop_id: Optional[str]
stop_name: Optional[str]
route_id: Optional[str]
tooltip: Optional[Tooltip]
avg_mph: Optional[float]
p20_mph: Optional[float] = Field(alias="_20p_mph")
# we add alpha in the JS if only 3 colors are passed
color: Optional[conlist(int, min_items=3, max_items=4)]
highlight_color: Optional[conlist(int, min_items=3, max_items=4)]
color: Color
highlight_color: Color

@root_validator
def some_identifier_exists(cls, values):
Expand Down Expand Up @@ -89,7 +96,10 @@ def validate_geojson(

collection = FeatureCollection(**d)

layer_type_class = LAYER_FEATURE_TYPES.get(layer_type, Feature[Geometry, Dict])
if layer_type:
layer_type_class = LAYER_FEATURE_TYPES.get(layer_type, Feature[Geometry, Dict])
else:
layer_type_class = Feature[Geometry, Dict]

if verbose:
typer.secho(
Expand Down Expand Up @@ -117,13 +127,18 @@ class BasemapConfig(BaseModel):
options: Dict[str, Any]


if TYPE_CHECKING:
LayerList = list[Layer]
else:
# this will not render in erdantic; needs to be List[Layer] but then pydantic2ts will not set min_items
LayerList = conlist(Layer, min_items=1)


# Any positions in this are flipped from typical geojson
# leaflet wants lat/lon
class State(BaseModel):
name: Optional[str]
layers: conlist(
Layer, min_items=1
) # this will not render in erdantic; needs to be List[Layer] but then pydantic2ts will not set min_items
layers: LayerList
lat_lon: Optional[Position]
zoom: Optional[int]
bbox: Optional[Tuple[Position, Position]]
Expand Down Expand Up @@ -151,7 +166,7 @@ def validate_layers(
if data:
validate_geojson(layer.url, layer.typ, verbose=verbose)

def iframe_url(self, host: str = None) -> str:
def iframe_url(self, host: Optional[str] = None) -> str:
host = host or MAP_APP_URL
if not host:
raise RuntimeError(
Expand Down

0 comments on commit 48f0ecf

Please sign in to comment.