Skip to content

Commit 093f143

Browse files
authored
chore: update ci pipeline and poetry version (#160)
* chore: update ci pipeline and poetry version - Introduce dependencies' caching, python black testing and pytest in ci pipeline. Set the ubuntu agent to an explicit version. - Bump poetry version to 1.8.2, and bump all dev dependencies to their latest. Update flask to use <3.0.0 version. Following this version, the Markup module is not include in Flask anymore. - Run `black -l 80` on project - Update __version__ in __init__.py to "0.4.1" to make the test successful. (I don't see the functionality of this test. I will consider removing it in the next PR). * chore: fix PR review comments - Update Makefile to include all CI steps. Introduce `black` and `quality` tasks. The latter runs `black` and `pep8` tasks. - Update ci.yaml to include make tasks include of raw commands - Fix `black` related findings (i.e. mainly F401 ones). The F401 findings were related with typing module, so instructed `black` to ignore those.
1 parent 6d89169 commit 093f143

File tree

10 files changed

+1225
-1391
lines changed

10 files changed

+1225
-1391
lines changed

.github/workflows/ci.yaml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ jobs:
66
test:
77
runs-on: ubuntu-latest
88
strategy:
9-
fail-fast: false
9+
fail-fast: true
1010
matrix:
11-
python: ["3.6", "3.7", "3.8"]
11+
python: ["3.9", "3.10", "3.11", "3.12"]
12+
poetry-version: [1.8.2]
1213

1314
steps:
14-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1516
with:
1617
fetch-depth: 1
1718

18-
- name: Set up Python
19-
uses: actions/setup-python@v1
19+
- name: Set up Poetry ${{ matrix.poetry-version }}
20+
uses: abatilo/actions-poetry@v2.0.0
21+
with:
22+
poetry-version: ${{ matrix.poetry-version }}
23+
24+
- name: Set up Python ${{ matrix.python }}
25+
uses: actions/setup-python@v5
2026
with:
2127
python-version: ${{ matrix.python }}
28+
cache: 'poetry'
29+
cache-dependency-path: poetry.lock
2230

23-
- name: Install Dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install -r requirements.txt
31+
- name: Install dependencies
32+
run: make install
2733

2834
- name: Code Quality
29-
run: |
30-
pip install black
31-
black -l 80 --check
35+
run: make quality
36+
37+
- name: Unit tests
38+
run: make test

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
.PHONY: test pep8 types clean install build publish tree env
1+
.PHONY: test quality pep8 black types clean install build publish tree env
22

3-
test: pep8
4-
py.test --cov=flask_googlemaps -l --tb=short --maxfail=1 tests/
3+
test:
4+
@poetry run pytest --cov .
5+
6+
quality: pep8 black
57

68
pep8:
7-
@flake8 flask_googlemaps --ignore=F403
9+
@poetry run flake8 flask_googlemaps --ignore=F403
10+
11+
black:
12+
@poetry run black -l 80 --check .
813

914
types:
1015
@mypy --py2 flask_googlemaps

examples/example.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from flask import Flask, render_template, request
44
from flask_googlemaps import GoogleMaps
55
from flask_googlemaps import Map, icons
6-
#from dynaconf import FlaskDynaconf
6+
7+
# from dynaconf import FlaskDynaconf
78

89
app = Flask(__name__, template_folder="templates")
9-
#FlaskDynaconf(app) # will read GOOGLEMAPS_KEY from .secrets.toml
10+
# FlaskDynaconf(app) # will read GOOGLEMAPS_KEY from .secrets.toml
1011

1112

1213
# you can set key as config
@@ -148,7 +149,11 @@ def mapview():
148149
varname="circlemap",
149150
lat=33.678,
150151
lng=-116.243,
151-
circles=[circle, [33.685, -116.251, 1000], (33.685, -116.251, 1500),],
152+
circles=[
153+
circle,
154+
[33.685, -116.251, 1000],
155+
(33.685, -116.251, 1500),
156+
],
152157
)
153158

154159
polyline = {

examples/example_2.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from flask import Flask, render_template
22
from flask_googlemaps import GoogleMaps, Map, icons
3-
#from dynaconf import FlaskDynaconf
4-
#enter the api key below
5-
api = ''
3+
4+
# from dynaconf import FlaskDynaconf
5+
# enter the api key below
6+
api = ""
67
app = Flask(__name__)
7-
GoogleMaps(app, key = api)
8-
#FlaskDynaconf(app)
8+
GoogleMaps(app, key=api)
9+
# FlaskDynaconf(app)
910

1011
import json
1112

1213

1314
@app.route("/")
1415
def map_created_in_view():
1516

16-
with open('dark_mode.json') as d:
17+
with open("dark_mode.json") as d:
1718
dark_data = json.load(d)
1819

1920
wmap = Map(
@@ -26,10 +27,9 @@ def map_created_in_view():
2627
icons.dots.blue: [(37.4300, -122.1400, "Hello World")],
2728
},
2829
style="height:400px;width:600px;margin:0;color:#242f3e;",
29-
bicycle_layer = True,
30+
bicycle_layer=True,
3031
)
3132

32-
3333
gmap = Map(
3434
identifier="gmap",
3535
varname="gmap",
@@ -40,7 +40,7 @@ def map_created_in_view():
4040
icons.dots.blue: [(37.4300, -122.1400, "Hello World")],
4141
},
4242
style="height:400px;width:600px;margin:0;color:#242f3e;",
43-
layer = "https://geo.data.gov.sg/dengue-cluster/2020/09/02/kml/dengue-cluster.kml"
43+
layer="https://geo.data.gov.sg/dengue-cluster/2020/09/02/kml/dengue-cluster.kml",
4444
)
4545

4646
dmap = Map(
@@ -54,11 +54,12 @@ def map_created_in_view():
5454
},
5555
style="height:400px;width:600px;margin:0;color:#242f3e;",
5656
styles=dark_data,
57-
5857
)
5958

60-
# print(get_address(api, 22.4761596, 88.4149326))
61-
return render_template("example_2.html", dmap=dmap ,gmap = gmap, wmap = wmap,key = api)
59+
# print(get_address(api, 22.4761596, 88.4149326))
60+
return render_template(
61+
"example_2.html", dmap=dmap, gmap=gmap, wmap=wmap, key=api
62+
)
6263

6364

6465
if __name__ == "__main__":

examples/jsonify_examples.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ def circle_view():
154154
varname="circlemap",
155155
lat=33.678,
156156
lng=-116.243,
157-
circles=[circle, [33.685, -116.251, 1000], (33.685, -116.251, 1500),],
157+
circles=[
158+
circle,
159+
[33.685, -116.251, 1000],
160+
(33.685, -116.251, 1500),
161+
],
158162
)
159163

160164
return jsonify(circlemap.as_json())

flask_googlemaps/__init__.py

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""FlaskGoogleMaps - Google Maps Extension for Flask"""
22

3-
__version__ = "0.4.0"
3+
__version__ = "0.4.1"
44

55
from json import dumps
6-
from typing import Optional, Dict, Any, List, Union, Tuple, Text
6+
from typing import Optional, Dict, Any, List, Union, Tuple, Text # noqa: F401
7+
78
import requests
89
from flask import Blueprint, Markup, g, render_template
910

10-
from flask_googlemaps.icons import dots, Icon
11+
from flask_googlemaps.icons import dots, Icon # noqa: F401
1112

1213
DEFAULT_ICON = dots.red
1314
DEFAULT_CLUSTER_IMAGE_PATH = "static/images/m"
@@ -27,7 +28,8 @@ def __init__(
2728
cls="map", # type: str
2829
language="en", # type: str
2930
region="US", # type: str
30-
rectangles=None, # type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
31+
rectangles=None,
32+
# type: Optional[List[Union[List, Tuple, Tuple[Tuple], Dict]]]
3133
circles=None, # type: Optional[List[Union[List, Tuple, Dict]]]
3234
polylines=None, # type: Optional[List[Union[List, Tuple, Dict]]]
3335
polygons=None, # type: Optional[List[Union[List, Tuple, Dict]]]
@@ -256,13 +258,20 @@ def build_rectangle_dict(
256258
"stroke_weight": stroke_weight,
257259
"fill_color": fill_color,
258260
"fill_opacity": fill_opacity,
259-
"bounds": {"north": north, "west": west, "south": south, "east": east},
261+
"bounds": {
262+
"north": north,
263+
"west": west,
264+
"south": south,
265+
"east": east,
266+
},
260267
}
261268

262269
return rectangle
263270

264-
def add_rectangle(self, north=None, west=None, south=None, east=None, **kwargs):
265-
# type: (Optional[float], Optional[float], Optional[float], Optional[float], **Any) -> None
271+
def add_rectangle(
272+
self, north=None, west=None, south=None, east=None, **kwargs
273+
):
274+
# type: (Optional[float], Optional[float], Optional[float], Optional[float], **Any) -> None # noqa: E501
266275
"""Adds a rectangle dict to the Map.rectangles attribute
267276
268277
The Google Maps API describes a rectangle using the LatLngBounds
@@ -297,7 +306,9 @@ def add_rectangle(self, north=None, west=None, south=None, east=None, **kwargs):
297306
if east:
298307
kwargs["bounds"]["east"] = east
299308

300-
if set(("north", "east", "south", "west")) != set(kwargs["bounds"].keys()):
309+
if set(("north", "east", "south", "west")) != set(
310+
kwargs["bounds"].keys()
311+
):
301312
raise AttributeError("rectangle bounds required to rectangles")
302313

303314
kwargs.setdefault("stroke_color", "#FF0000")
@@ -346,7 +357,9 @@ def build_circles(self, circles):
346357
elif isinstance(circle, (tuple, list)):
347358
if len(circle) != 3:
348359
raise AttributeError("circle requires center and radius")
349-
circle_dict = self.build_circle_dict(circle[0], circle[1], circle[2])
360+
circle_dict = self.build_circle_dict(
361+
circle[0], circle[1], circle[2]
362+
)
350363
self.add_circle(**circle_dict)
351364

352365
def build_circle_dict(
@@ -395,7 +408,9 @@ def build_circle_dict(
395408

396409
return circle
397410

398-
def add_circle(self, center_lat=None, center_lng=None, radius=None, **kwargs):
411+
def add_circle(
412+
self, center_lat=None, center_lng=None, radius=None, **kwargs
413+
):
399414
# type: (Optional[float], Optional[float], Optional[float], **Any) -> None
400415
"""Adds a circle dict to the Map.circles attribute
401416
@@ -744,14 +759,16 @@ def build_heatmap(self, heatmap_data, heatmap_layer):
744759
raise AttributeError("heatmap_later requires 'heatmap_data'")
745760
if not isinstance(heatmap_data, (list)):
746761
raise AttributeError(
747-
"heatmap_data only accepts a list of dicts with keys 'lat' 'lng' and their corresponding values"
762+
"heatmap_data only accepts a list of dicts with keys "
763+
"'lat' 'lng' and their corresponding values"
748764
)
749765
for hm in heatmap_data:
750766
if isinstance(hm, dict):
751767
self.add_heatmap(**hm)
752768
else:
753769
raise AttributeError(
754-
"elements of list 'heatmap_data' must be a dict of keys 'lat' and 'lng' with their corresponding values"
770+
"elements of list 'heatmap_data' must be a dict of keys "
771+
"'lat' and 'lng' with their corresponding values"
755772
)
756773

757774
def add_heatmap(self, lat=None, lng=None, **kwargs):
@@ -763,7 +780,9 @@ def add_heatmap(self, lat=None, lng=None, **kwargs):
763780
if "lat" not in kwargs or "lng" not in kwargs:
764781
raise AttributeError("heatmap_data requires 'lat' and 'lng' values")
765782
if len(kwargs) > 2:
766-
raise AttributeError("heatmap_data can only contain 'lat' and 'lng' values")
783+
raise AttributeError(
784+
"heatmap_data can only contain 'lat' and 'lng' values"
785+
)
767786

768787
self.heatmap_data.append(kwargs)
769788

@@ -820,7 +839,9 @@ def verify_lat_lng_coordinates(self, lat, lng):
820839
def js(self):
821840
# type: () -> Markup
822841
return Markup(
823-
self.render("googlemaps/gmapjs.html", gmap=self, DEFAULT_ICON=DEFAULT_ICON)
842+
self.render(
843+
"googlemaps/gmapjs.html", gmap=self, DEFAULT_ICON=DEFAULT_ICON
844+
)
824845
)
825846

826847
@property
@@ -860,18 +881,30 @@ def set_googlemaps_loaded():
860881
def get_address(API_KEY, lat, lon):
861882
# type: (str, float, float) -> dict
862883
add_dict = dict()
863-
response = rq.get(
884+
response = requests.get(
864885
"https://maps.googleapis.com/maps/api/geocode/json?latlng="
865886
+ ",".join(map(str, [lat, lon]))
866887
+ "&key="
867888
+ API_KEY
868889
).json()
869-
add_dict["zip"] = response["results"][0]["address_components"][-1]["long_name"]
870-
add_dict["country"] = response["results"][0]["address_components"][-2]["long_name"]
871-
add_dict["state"] = response["results"][0]["address_components"][-3]["long_name"]
872-
add_dict["city"] = response["results"][0]["address_components"][-4]["long_name"]
873-
add_dict["locality"] = response["results"][0]["address_components"][-5]["long_name"]
874-
add_dict["road"] = response["results"][0]["address_components"][-6]["long_name"]
890+
add_dict["zip"] = response["results"][0]["address_components"][-1][
891+
"long_name"
892+
]
893+
add_dict["country"] = response["results"][0]["address_components"][-2][
894+
"long_name"
895+
]
896+
add_dict["state"] = response["results"][0]["address_components"][-3][
897+
"long_name"
898+
]
899+
add_dict["city"] = response["results"][0]["address_components"][-4][
900+
"long_name"
901+
]
902+
add_dict["locality"] = response["results"][0]["address_components"][-5][
903+
"long_name"
904+
]
905+
add_dict["road"] = response["results"][0]["address_components"][-6][
906+
"long_name"
907+
]
875908
add_dict["formatted_address"] = response["results"][0]["formatted_address"]
876909
return add_dict
877910

@@ -909,7 +942,9 @@ def init_app(self, app):
909942
app.add_template_global(googlemap_obj)
910943
app.add_template_filter(googlemap)
911944
app.add_template_global(googlemap)
912-
app.add_template_global(app.config.get("GOOGLEMAPS_KEY"), name="GOOGLEMAPS_KEY")
945+
app.add_template_global(
946+
app.config.get("GOOGLEMAPS_KEY"), name="GOOGLEMAPS_KEY"
947+
)
913948
app.add_template_global(set_googlemaps_loaded)
914949
app.add_template_global(is_googlemaps_loaded)
915950

flask_googlemaps/icons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__all__ = ["dots", "alpha", "shapes", "pushpin", "paddle"]
1111

12-
from typing import Optional, List
12+
from typing import Optional, List # noqa: F401
1313

1414

1515
class Icon(object):

flask_googlemaps/tests/test_map.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class TestFunctionAddMarker:
66
"""
7-
This Class is to test function add marker.
7+
This Class is to test function add marker.
88
"""
99

1010
google_map = None
@@ -21,8 +21,8 @@ def config_test(self):
2121
@pytest.mark.parametrize("marker", [{}, {"lat": 1}, {"lng": 1}])
2222
def test_should_raise_attribute_error_when_is_missing_params(self, marker):
2323
"""
24-
Test check the validation of marker.
25-
This should raise expetion when the lat, lng or both are missing.
24+
Test check the validation of marker.
25+
This should raise expetion when the lat, lng or both are missing.
2626
"""
2727
with pytest.raises(AttributeError) as error:
2828
self.google_map.add_marker(**marker)
@@ -38,7 +38,7 @@ def test_should_raise_attribute_error_when_is_missing_params(self, marker):
3838
)
3939
def test_it_should_add_to_marker_list_a_new_valid_marker(self, marker):
4040
"""
41-
Test check if add_marker is adding a new market to markers_list.
41+
Test check if add_marker is adding a new market to markers_list.
4242
"""
4343
self.google_map.add_marker(**marker)
4444
assert len(self.google_map.markers) == 1

0 commit comments

Comments
 (0)