From 9694a07b5fc7e827f276bdb42bad9575e5a76836 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 7 Dec 2024 18:50:09 -0500 Subject: [PATCH 1/4] First cut of database library upgrade --- requirements.txt | 6 +++--- setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 65b8526..9c03c34 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ Flask==3.1.0 -GeoAlchemy @ https://github.com/hozn/GeoAlchemy/archive/0.7.3dev1.tar.gz +GeoAlchemy2==0.16.0 PyMySQL==1.1.1 PyYAML==6.0.2 -SQLAlchemy==1.3.24 +SQLAlchemy==1.4.54 # Thanks https://stackoverflow.com/a/77214086/424301 - Flask did not pin Werkzeug dep Werkzeug==3.1.3 arrow==0.15.5 @@ -10,7 +10,7 @@ autoflake==2.2.1 beautifulsoup4==4.12.3 colorlog==4.1.0 envparse==0.2.0 -freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.8.6.tar.gz +freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.10.3.tar.gz geojson==2.5.0 gunicorn==23.0.0 marshmallow==3.23.1 diff --git a/setup.py b/setup.py index 888a92b..2b3c25c 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ install_req = [ "Flask", - "GeoAlchemy", + "GeoAlchemy2", "PyMySQL", "PyYAML", "alembic", From a091259d34730bc662dc04c7080a06e5a22c22a4 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 7 Dec 2024 19:46:12 -0500 Subject: [PATCH 2/4] Use latest model, defensive programming I'm not sure the ALembic config is relevant anymore but update it just in case with what works in freezing-model --- alembic.ini | 5 +++-- freezing/web/version.py | 31 ++++++++++++++++++++----------- requirements.txt | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/alembic.ini b/alembic.ini index eb43cc0..e3d9515 100644 --- a/alembic.ini +++ b/alembic.ini @@ -2,7 +2,7 @@ [alembic] # path to migration scripts -script_location = alembic +script_location = freezing.model:migrations # template used to generate migration files # file_template = %%(rev)s_%%(slug)s @@ -15,7 +15,8 @@ script_location = alembic # the 'revision' command, regardless of autogenerate # revision_environment = false -# This is read from Flask config instead +# This is read from Flask config instead, +# or set the SQLALCHEMY_URL environment variable # sqlalchemy.url = driver://user:pass@localhost/dbname diff --git a/freezing/web/version.py b/freezing/web/version.py index 2c559b7..859a864 100644 --- a/freezing/web/version.py +++ b/freezing/web/version.py @@ -7,25 +7,34 @@ # frozen values of commit, build_date, and branch. import datetime +import logging import subprocess # Thanks https://stackoverflow.com/a/21901260/424301 def get_git_revision_short_hash() -> str: - return ( - subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) - .decode("ascii") - .strip() - ) + try: + return ( + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) + .decode("ascii") + .strip() + ) + except Exception as e: + logging.warning(f"Could not get revision from git {e}") + return "unknown" def get_git_branch() -> str: - return ( - subprocess.check_output(["git", "symbolic-ref", "-q", "HEAD"]) - .decode("ascii") - .strip() - .replace("refs/heads/", "") - ) + try: + return ( + subprocess.check_output(["git", "symbolic-ref", "-q", "HEAD"]) + .decode("ascii") + .strip() + .replace("refs/heads/", "") + ) + except Exception as e: + logging.warning(f"Could not get branch from git {e}") + return "unknown" def freeze(): diff --git a/requirements.txt b/requirements.txt index 9c03c34..ebc3d6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ autoflake==2.2.1 beautifulsoup4==4.12.3 colorlog==4.1.0 envparse==0.2.0 -freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.10.3.tar.gz +freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.10.4.tar.gz geojson==2.5.0 gunicorn==23.0.0 marshmallow==3.23.1 From 72d5c8d4c62f903701c56d6be3360fb2a306ea63 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 7 Dec 2024 21:12:38 -0500 Subject: [PATCH 3/4] Upgrade to geoalchemy2 --- Dockerfile | 1 + freezing/web/data.py | 10 +++++----- freezing/web/version.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c01386a..aeb19e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN pip3 install -r /tmp/requirements.txt ADD . /app RUN mkdir -p /data COPY leaderboards /data/leaderboards +COPY alembic.ini /app WORKDIR /app RUN pip3 install . ENV LEADERBOARDS_DIR=/data/leaderboards diff --git a/freezing/web/data.py b/freezing/web/data.py index d15dfb8..e41ea1b 100644 --- a/freezing/web/data.py +++ b/freezing/web/data.py @@ -17,7 +17,7 @@ RideTrack, Team, ) -from geoalchemy import WKTSpatialElement +from geoalchemy2 import WKTElement from instagram import InstagramAPIError, InstagramClientError from requests.exceptions import HTTPError from sqlalchemy import and_ @@ -343,7 +343,7 @@ def write_ride(activity): """ if activity.start_latlng: - start_geo = WKTSpatialElement( + start_geo = WKTElement( "POINT({lon} {lat})".format( lat=activity.start_latlng.lat, lon=activity.start_latlng.lon ) @@ -352,7 +352,7 @@ def write_ride(activity): start_geo = None if activity.end_latlng: - end_geo = WKTSpatialElement( + end_geo = WKTElement( "POINT({lon} {lat})".format( lat=activity.end_latlng.lat, lon=activity.end_latlng.lon ) @@ -546,7 +546,7 @@ def write_ride_efforts(strava_activity, ride): # if strava_activity.map.polyline: # latlon_points = PolylineCodec().decode(strava_activity.map.polyline) # lonlat_points = [(lon,lat) for (lat,lon) in latlon_points] -# gps_track = WKTSpatialElement(wktutils.linestring_wkt(lonlat_points)) +# gps_track = WKTElement(wktutils.linestring_wkt(lonlat_points)) # else: # gps_track = None # @@ -586,7 +586,7 @@ def write_ride_streams(streams, ride): RideTrack.__table__.delete().where(RideTrack.ride_id == ride.id) ) - gps_track = WKTSpatialElement(wktutils.linestring_wkt(lonlat_points)) + gps_track = WKTElement(wktutils.linestring_wkt(lonlat_points)) ride_track = RideTrack() ride_track.gps_track = gps_track diff --git a/freezing/web/version.py b/freezing/web/version.py index 859a864..d0ccd48 100644 --- a/freezing/web/version.py +++ b/freezing/web/version.py @@ -7,7 +7,7 @@ # frozen values of commit, build_date, and branch. import datetime -import logging +from freezing.web.autolog import log import subprocess @@ -20,7 +20,7 @@ def get_git_revision_short_hash() -> str: .strip() ) except Exception as e: - logging.warning(f"Could not get revision from git {e}") + log.warning(f"Could not get revision from git {e}") return "unknown" @@ -33,7 +33,7 @@ def get_git_branch() -> str: .replace("refs/heads/", "") ) except Exception as e: - logging.warning(f"Could not get branch from git {e}") + log.warning(f"Could not get branch from git {e}") return "unknown" From 70d19c2219954151454f0174d3b83ef1387e1e3d Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 7 Dec 2024 21:22:13 -0500 Subject: [PATCH 4/4] Fix isort --- freezing/web/version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freezing/web/version.py b/freezing/web/version.py index d0ccd48..3416e80 100644 --- a/freezing/web/version.py +++ b/freezing/web/version.py @@ -7,9 +7,10 @@ # frozen values of commit, build_date, and branch. import datetime -from freezing.web.autolog import log import subprocess +from freezing.web.autolog import log + # Thanks https://stackoverflow.com/a/21901260/424301 def get_git_revision_short_hash() -> str: