Skip to content

Commit

Permalink
Merge branch 'master' into fix-138
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Caha committed Sep 4, 2024
2 parents a078322 + b84d41d commit 5ba329c
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:

- name: Install dependencies
run: |
python -m pip install dynaconf pyinstaller mergin-client psycopg2
python -m pip install -r requirements.txt
python -m pip install pyinstaller
- name: Build Binary
run: |
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/tests_mergin_db_sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
paths:
- "test/**"
- "**.py"
- "requirements.txt"
- "requirements-dev.txt"
- "pyproject.toml"
- ".github/workflows/tests_mergin_db_sync.yaml"

env:
Expand Down Expand Up @@ -46,14 +49,15 @@ jobs:
- name: Check Geodiff version
run: geodiff version

- name: Checkout
uses: actions/checkout@v4

- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install mergin-client pytest pytest-cov dynaconf psycopg2
- name: Checkout
uses: actions/checkout@v4
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt
- name: Run tests
run: |
Expand Down
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile

from dynaconf import Dynaconf
import dynaconf

from smtp_functions import create_connection_and_log_user

Expand Down Expand Up @@ -158,6 +159,10 @@ def get_ignored_tables(
connection.skip_tables,
list,
):
if len(connection.skip_tables) < 1:
return []
elif isinstance(connection.skip_tables, dynaconf.vendor.box.box_list.BoxList):
return connection.skip_tables.to_list()
return connection.skip_tables
else:
return []
Expand Down
40 changes: 16 additions & 24 deletions dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,7 @@ def _print_mergin_changes(
cached_mergin_project_objects = {}


def _get_mergin_project(
work_path,
):
def _get_mergin_project(work_path) -> MerginProject:
"""
Returns a cached MerginProject object or creates one if it does not exist yet.
This is to avoid creating many of these objects (e.g. every pull/push) because it does
Expand All @@ -538,23 +536,20 @@ def _get_mergin_project(
"""
if work_path not in cached_mergin_project_objects:
cached_mergin_project_objects[work_path] = MerginProject(work_path)
cached_mergin_project_objects[work_path]._read_metadata()
return cached_mergin_project_objects[work_path]


def _get_project_version(
work_path,
):
def _get_project_version(work_path) -> str:
"""Returns the current version of the project"""
mp = _get_mergin_project(work_path)
return mp.metadata["version"]
return mp.version()


def _get_project_id(
mp,
):
def _get_project_id(mp: MerginProject):
"""Returns the project ID"""
try:
project_id = uuid.UUID(mp.metadata["project_id"])
project_id = uuid.UUID(mp.project_id())
except (
KeyError,
ValueError,
Expand Down Expand Up @@ -636,10 +631,9 @@ def _validate_local_project_id(
local_project_id = _get_project_id(mp)
if local_project_id is None:
return
project_path = mp.metadata["name"]
if server_info is None:
try:
server_info = mc.project_info(project_path)
server_info = mc.project_info(mp.project_full_name())
except ClientError as e:
raise DbSyncError("Mergin Maps client error: " + str(e))

Expand Down Expand Up @@ -718,7 +712,7 @@ def revert_local_changes(
mp.dir,
update_delete_file,
update_delete_filepath,
mp.metadata["version"],
mp.version(),
)
except ClientError as e:
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down Expand Up @@ -754,12 +748,11 @@ def pull(conn_cfg, mc):
# Make sure that local project ID (if available) is the same as on the server
_validate_local_project_id(mp, mc)

project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
local_version = mp.version()

try:
projects = mc.get_projects_by_names([project_path])
server_version = projects[project_path]["version"]
projects = mc.get_projects_by_names([mp.project_full_name()])
server_version = projects[mp.project_full_name()]["version"]
except ClientError as e:
# this could be e.g. DNS error
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down Expand Up @@ -900,8 +893,8 @@ def status(conn_cfg, mc):
mp.set_tables_to_skip(ignored_tables)
if mp.geodiff is None:
raise DbSyncError("Mergin Maps client installation problem: geodiff not available")
project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
project_path = mp.project_full_name()
local_version = mp.version()
logging.debug("Checking status...")
try:
server_info = mc.project_info(
Expand Down Expand Up @@ -1009,12 +1002,11 @@ def push(conn_cfg, mc):
# Make sure that local project ID (if available) is the same as on the server
_validate_local_project_id(mp, mc)

project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
local_version = mp.version()

try:
projects = mc.get_projects_by_names([project_path])
server_version = projects[project_path]["version"]
projects = mc.get_projects_by_names([mp.project_full_name()])
server_version = projects[mp.project_full_name()]["version"]
except ClientError as e:
# this could be e.g. DNS error
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest>=6.2
pytest-cov>=3.0
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mergin-client>=0.8.3
mergin-client==0.9.0
dynaconf>=3.1
psycopg2>=2.9
Loading

0 comments on commit 5ba329c

Please sign in to comment.