Skip to content

Commit

Permalink
Geopackage support (#357)
Browse files Browse the repository at this point in the history
Update modelchecker to work with schema 220
  • Loading branch information
margrietpalm authored Mar 12, 2024
1 parent a735f18 commit 746c472
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 32 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ jobs:
include:
# 2019
- python: 3.8
pins: "sqlalchemy==1.4.0 alembic==1.8.* geoalchemy2==0.9.* rasterio==1.3.0"
pins: "sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.14.* rasterio==1.3.0"
# 2021
- python: 3.9
pins: "sqlalchemy==1.4.30 alembic==1.8.* geoalchemy2==0.10.* rasterio==1.3.3"
pins: "sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.14.* rasterio==1.3.3"
# 2022
- python: "3.10"
pins: "sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.12.* rasterio==1.3.5.post1"
# current
pins: "sqlalchemy==1.4.44 alembic==1.8.* geoalchemy2==0.14.* rasterio==1.3.5.post1"
# 2023
- python: "3.11"
pins: ""
pins: "sqlalchemy==2.0.24 alembic==1.13.1 geoalchemy2==0.14.3 rasterio==1.3.9"
# current
- python: "3.12"
#pins: "sqlalchemy==2.0.* alembic==1.13.* geoalchemy2==0.14.* rasterio==1.3.9.*"

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Changelog of threedi-modelchecker

2.6.3 (unreleased)
------------------

- Nothing changed yet.
- Support geopackage
- Support changes in threedi-schema (0.220) needed for geopackage support


2.6.2 (2024-02-29)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"Click",
"GeoAlchemy2>=0.9,!=0.11.*",
"SQLAlchemy>=1.4",
"threedi-schema==0.219.*",
"threedi-schema==0.220.*"
]

[project.optional-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Click
GeoAlchemy2>=0.9,!=0.11.*
SQLAlchemy>=1.2
GeoAlchemy2>=0.14
SQLAlchemy>=1.4.44
Click==7.0
alembic>=0.9
alembic>=1.8
6 changes: 4 additions & 2 deletions threedi_modelchecker/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def __init__(self, *args, **kwargs):
self.expected_types = _sqlalchemy_to_sqlite_types(self.column.type)

def get_invalid(self, session):
if "sqlite" not in session.bind.dialect.dialect_description:
if ("sqlite" not in session.bind.dialect.dialect_description) and (
"geopackage" not in session.bind.dialect.dialect_description
):
return []
q_invalid = self.to_check(session)
invalid_type_query = q_invalid.filter(
Expand Down Expand Up @@ -311,7 +313,7 @@ def description(self):
def _get_geometry_type(column, dialect):
if column.type.geometry_type == "GEOMETRY":
return # should skip the check
if dialect == "sqlite":
if dialect in ["sqlite", "geopackage"]:
return column.type.geometry_type
elif dialect == "postgresql":
geom_type = column.type.geometry_type.capitalize()
Expand Down
10 changes: 0 additions & 10 deletions threedi_modelchecker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,6 @@ def is_none_or_empty(col):
LinestringLocationCheck(error_code=205, column=table.the_geom, max_distance=1)
for table in [models.Channel, models.Culvert]
]
CHECKS += [
QueryCheck(
error_code=206,
column=models.ConnectionNode.the_geom_linestring,
invalid=Query(models.ConnectionNode).filter(
models.ConnectionNode.the_geom_linestring != None
),
message=f"{models.ConnectionNode.the_geom_linestring} must be NULL",
)
]
CHECKS += [
SpatialIndexCheck(
error_code=207, column=models.ConnectionNode.the_geom, level=CheckLevel.WARNING
Expand Down
10 changes: 5 additions & 5 deletions threedi_modelchecker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def threedi_db(tmpdir_factory):
https://factoryboy.readthedocs.io/en/latest/orms.html#managing-sessions
"""
tmp_path = tmpdir_factory.mktemp("spatialite4")
tmp_sqlite = tmp_path / "empty_v4.sqlite"
shutil.copyfile(data_dir / "empty_v4.sqlite", tmp_sqlite)
tmp_sqlite = tmp_path / "empty.gpkg"
shutil.copyfile(data_dir / "empty.gpkg", tmp_sqlite)
db = ThreediDatabase(tmp_sqlite)
schema = ModelSchema(db)
schema.upgrade(backup=False, upgrade_spatialite_version=False)
Expand Down Expand Up @@ -52,7 +52,7 @@ def session(threedi_db):

@pytest.fixture
def empty_sqlite_v4(tmp_path):
"""An function-scoped empty spatialite v4 in the latest migration state"""
tmp_sqlite = tmp_path / "empty_v4.sqlite"
shutil.copyfile(data_dir / "empty_v4.sqlite", tmp_sqlite)
"""An function-scoped empty geopackage v4 in the latest migration state"""
tmp_sqlite = tmp_path / "empty.gpkg"
shutil.copyfile(data_dir / "empty.gpkg", tmp_sqlite)
return ThreediDatabase(tmp_sqlite)
Binary file added threedi_modelchecker/tests/data/empty.gpkg
Binary file not shown.
3 changes: 0 additions & 3 deletions threedi_modelchecker/tests/data/empty_v4.sqlite

This file was deleted.

2 changes: 1 addition & 1 deletion threedi_modelchecker/tests/test_checks_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_gen_not_null_checks():
def test_gen_geometry_check():
geometry_checks = generate_geometry_checks(models.ConnectionNode.__table__)

assert len(geometry_checks) == 2
assert len(geometry_checks) == 1
geometry_check_columns = [check.column for check in geometry_checks]
assert models.ConnectionNode.the_geom in geometry_check_columns

Expand Down

0 comments on commit 746c472

Please sign in to comment.