Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions mergin/merginproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,11 +1079,31 @@ def set_tables_to_skip(self, tables):

If empty list is passed, list will be reset.

This method is mutually exclusive with set_tables_to_include() and error
GeoDiffLibError will be raised if both are set.

:param tables: list of table names to ignore
:type tables: list[str]
"""
self.geodiff.set_tables_to_skip(tables)

def set_tables_to_include(self, tables: List[str]):
"""
Set list of tables to include in geodiff operations. Once defined, only these
tables will be included in the following operations: create changeset, apply
changeset, rebase, get database schema, dump database contents, copy database
between different drivers.

If empty list is passed, list will be reset.

This method is mutually exclusive with set_tables_to_skip() and error
GeoDiffLibError will be raised if both are set.

:param tables: list of table names to include
:type tables: list[str]
"""
self.geodiff.set_tables_to_include(tables)

def get_geodiff_changes_count(self, diff_rel_path: str):
"""
Best-effort: return number of changes in the .gpkg diff (int) or None.
Expand Down
53 changes: 53 additions & 0 deletions mergin/test/test_mergin_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
import pytest
from mergin.merginproject import MerginProject
from pygeodiff import GeoDiffLibError
from mergin.common import DeltaChangeType, PullActionType, ClientError
from mergin.models import ProjectDeltaChange, ProjectDeltaItemDiff
from mergin.client_pull import PullAction
Expand Down Expand Up @@ -418,3 +419,55 @@ def username(self):
assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-server.diff"))
assert not mp.geodiff.has_changes(os.path.join(tmp_dir, "live-base.diff"))
assert mp.geodiff.has_changes(os.path.join(tmp_dir, "live-conflict.diff"))


def test_set_tables_to_skip():
"""Tables in set_tables_to_skip are excluded from changeset creation."""
base = os.path.join(TEST_DATA_DIR, "two_tables.gpkg")
modified = os.path.join(TEST_DATA_DIR, "two_tables_1_A.gpkg")

with tempfile.TemporaryDirectory() as tmp_dir:
mp = MerginProject(tmp_dir)
diff = os.path.join(tmp_dir, "diff.diff")

mp.geodiff.create_changeset(base, modified, diff)
assert mp.geodiff.has_changes(diff)

mp.set_tables_to_skip(["survey"])
mp.geodiff.create_changeset(base, modified, diff)
assert not mp.geodiff.has_changes(diff)

mp.set_tables_to_skip([])
mp.geodiff.create_changeset(base, modified, diff)
assert mp.geodiff.has_changes(diff)


def test_set_tables_to_include():
"""Only tables in set_tables_to_include appear in the changeset."""
base = os.path.join(TEST_DATA_DIR, "two_tables.gpkg")
modified = os.path.join(TEST_DATA_DIR, "two_tables_1_A.gpkg")

with tempfile.TemporaryDirectory() as tmp_dir:
mp = MerginProject(tmp_dir)
diff = os.path.join(tmp_dir, "diff.diff")

mp.set_tables_to_include(["simple"])
mp.geodiff.create_changeset(base, modified, diff)
assert not mp.geodiff.has_changes(diff)

mp.set_tables_to_include(["survey"])
mp.geodiff.create_changeset(base, modified, diff)
assert mp.geodiff.has_changes(diff)

mp.set_tables_to_include([])
mp.geodiff.create_changeset(base, modified, diff)
assert mp.geodiff.has_changes(diff)


def test_tables_to_skip_and_include_mutually_exclusive():
"""Setting both skip and include lists should raise an error."""
with tempfile.TemporaryDirectory() as tmp_dir:
mp = MerginProject(tmp_dir)
mp.set_tables_to_skip(["table_a"])
with pytest.raises(GeoDiffLibError):
mp.set_tables_to_include(["table_b"])
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="mergin-client",
version="0.13.1",
version="0.14.0",
url="https://github.com/MerginMaps/python-api-client",
license="MIT",
author="Lutra Consulting Ltd.",
Expand All @@ -16,7 +16,7 @@
platforms="any",
install_requires=[
"python-dateutil==2.8.2",
"pygeodiff==2.2.0",
"pygeodiff==2.3.0",
"pytz==2022.1",
"click==8.1.3",
],
Expand Down
Loading