diff --git a/mergin/merginproject.py b/mergin/merginproject.py index 87f3c5f..12d798f 100644 --- a/mergin/merginproject.py +++ b/mergin/merginproject.py @@ -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. diff --git a/mergin/test/test_mergin_project.py b/mergin/test/test_mergin_project.py index 6da69e7..97fe554 100644 --- a/mergin/test/test_mergin_project.py +++ b/mergin/test/test_mergin_project.py @@ -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 @@ -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"]) diff --git a/setup.py b/setup.py index 9e3ead7..24ee9ad 100644 --- a/setup.py +++ b/setup.py @@ -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.", @@ -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", ],