Skip to content

Commit

Permalink
don't instantiate geodiff library at the module level, create it inside
Browse files Browse the repository at this point in the history
function (refs #504)
  • Loading branch information
alexbruy authored and wonder-sk committed Oct 17, 2023
1 parent 572e87f commit ac56189
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Mergin/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

from .utils import pygeodiff, get_schema

geodiff = pygeodiff.GeoDiff()
geodiff.set_maximum_logger_level(10)

diff_layers_list = []


Expand Down Expand Up @@ -110,7 +107,7 @@ def parse_db_schema(db_file):
return tables


def parse_diff(diff_file):
def parse_diff(geodiff, diff_file):
"""
Parse binary GeoDiff changeset and return map of changes per table
as follows
Expand Down Expand Up @@ -258,7 +255,7 @@ def get_table_name(layer):
return table_name


def get_local_changes(db_file, mp):
def get_local_changes(geodiff, db_file, mp):
"""Creates changeset containing local changes in the given GPKG file."""
f_name = os.path.split(db_file)[1]
base_path = mp.fpath_meta(f_name)
Expand All @@ -274,15 +271,17 @@ def get_local_changes(db_file, mp):


def make_local_changes_layer(mp, layer):
geodiff = pygeodiff.GeoDiff()

layer_path = layer.source().split("|")[0]
base_file = mp.fpath_meta(os.path.split(layer_path)[1])
diff_path = get_local_changes(layer_path, mp)
diff_path = get_local_changes(geodiff, layer_path, mp)

if diff_path is None:
return None, f"Failed to retrieve changes, as there is no base file for layer '{layer.name()}'"

db_schema = parse_db_schema(layer_path)
diff = parse_diff(diff_path)
diff = parse_diff(geodiff, diff_path)
table_name = get_table_name(layer)

if not diff or table_name not in diff.keys():
Expand Down

0 comments on commit ac56189

Please sign in to comment.