From 01075ec5e64fafa374cc25390694974a3b9e9b29 Mon Sep 17 00:00:00 2001 From: rgermain Date: Fri, 13 Sep 2024 14:56:40 +0200 Subject: [PATCH 1/3] feat: add geometry field --- .gitignore | 1 + CHANGES.rst | 8 ++++++++ dbcut/__init__.py | 2 +- dbcut/database.py | 10 ++++++++-- dbcut/serializer.py | 4 ++++ requirements/base.txt | 3 ++- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 37fe67c..d708a34 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ var/ *.egg-info/ .installed.cfg *.egg +venv # PyInstaller # Usually these files are written by a python script from a template diff --git a/CHANGES.rst b/CHANGES.rst index 77c3b6f..2b7a82e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog `_, and this project adheres to `Semantic Versioning `_. +Version 0.6.2 +------------------ + +Released on September 13th 2024 + +Added +----- +- Geometry field in sqlalchemy Version 0.6.1.dev0 ------------------ diff --git a/dbcut/__init__.py b/dbcut/__init__.py index e935144..a613b63 100755 --- a/dbcut/__init__.py +++ b/dbcut/__init__.py @@ -3,6 +3,6 @@ from .compiler import * # noqa -__version__ = "0.6.1.dev0" +__version__ = "0.6.2" VERSION = __version__ SQLALCHEMY_VERSION = sqlalchemy.__version__ diff --git a/dbcut/database.py b/dbcut/database.py index ca5f1ee..da1d0a4 100644 --- a/dbcut/database.py +++ b/dbcut/database.py @@ -9,6 +9,7 @@ from contextlib import contextmanager import sqlalchemy +from geoalchemy2 import Geometry from sqlalchemy import MetaData, Table, create_engine, event, func, inspect from sqlalchemy.engine.url import make_url from sqlalchemy.ext.automap import automap_base, generate_relationship @@ -21,8 +22,13 @@ from .models import BaseDeclarativeMeta, BaseModel from .query import BaseQuery, QueryProperty from .session import SessionProperty -from .utils import (aslist, cached_property, create_directory, - generate_valid_index_name, to_unicode) +from .utils import ( + aslist, + cached_property, + create_directory, + generate_valid_index_name, + to_unicode, +) try: from easy_profile import SessionProfiler, StreamReporter diff --git a/dbcut/serializer.py b/dbcut/serializer.py index 8b807e4..06e3917 100644 --- a/dbcut/serializer.py +++ b/dbcut/serializer.py @@ -7,6 +7,8 @@ from io import open import yaml +from geoalchemy2 import WKBElement +from geoalchemy2.shape import to_shape from sqlalchemy.orm import Query from .utils import to_unicode @@ -49,6 +51,8 @@ def default(self, obj): pass elif hasattr(obj, "__iter__"): return list(item for item in obj) + elif isinstance(obj, WKBElement): + return str(to_shape(obj)) return super(JSONEncoder, self).default(obj) return JSONEncoder diff --git a/requirements/base.txt b/requirements/base.txt index 1d9ab4c..7798c2f 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,6 +1,7 @@ Click -SQLAlchemy +sqlalchemy<2.0 mlalchemy +geoalchemy2 pptree python-dotenv tabulate From 65d6b0f1c700654a42fc703b12b776deb5d5bfb0 Mon Sep 17 00:00:00 2001 From: rgermain Date: Fri, 13 Sep 2024 16:10:29 +0200 Subject: [PATCH 2/3] add shape --- requirements/base.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/base.txt b/requirements/base.txt index 7798c2f..01d59cd 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,6 +2,7 @@ Click sqlalchemy<2.0 mlalchemy geoalchemy2 +geoalchemy2[shapely] pptree python-dotenv tabulate From 7a20fe4e7ed076dddb86367302ac2620df5ad95e Mon Sep 17 00:00:00 2001 From: rgermain Date: Mon, 16 Sep 2024 16:24:00 +0200 Subject: [PATCH 3/3] fix: requirements and docker-compose --- requirements/base.txt | 2 +- scripts/run-test-with-docker.sh | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 01d59cd..073fd96 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,7 +2,7 @@ Click sqlalchemy<2.0 mlalchemy geoalchemy2 -geoalchemy2[shapely] +shapely pptree python-dotenv tabulate diff --git a/scripts/run-test-with-docker.sh b/scripts/run-test-with-docker.sh index e7dfe93..f2207ac 100755 --- a/scripts/run-test-with-docker.sh +++ b/scripts/run-test-with-docker.sh @@ -1,6 +1,13 @@ #!/usr/bin/env bash ROOT_PROJECT="$(dirname "$(dirname "${BASH_SOURCE[0]}")")" +if ! command -v "docker-compose" >/dev/null +then + compose="docker compose" +else + compose="docker-compose" +fi + export PYTHON_IMAGE=${PYTHON_IMAGE:-python:3.6} export POSTGRES_IMAGE=${POSTGRES_IMAGE:-postgres:9.6} @@ -34,7 +41,7 @@ _print() { printf "\033[1;32m%b\033[0m\n" "$1"; } _cleanup() { _print ":: Cleanup" - docker-compose down -v --remove-orphans + $compose down -v --remove-orphans } if [ "$1" = "cleanup" ]; then @@ -46,8 +53,8 @@ else _cleanup _print ":: Building image" - docker-compose build + $compose build _print ":: Running tests" - docker-compose run --rm app make test + $compose run --rm app make test fi