Skip to content

Commit 7dbed14

Browse files
committed
fix typo and some docstrings for localProjectChanges
1 parent 0119b7d commit 7dbed14

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

mergin/client_push.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import time
2323
from typing import List, Tuple, Optional, ByteString
2424

25-
from .local_changes import FileChange, LocalPojectChanges
25+
from .local_changes import FileChange, LocalProjectChanges
2626

2727
from .common import UPLOAD_CHUNK_ATTEMPT_WAIT, UPLOAD_CHUNK_ATTEMPTS, UPLOAD_CHUNK_SIZE, ClientError, ErrorCode
2828
from .merginproject import MerginProject
@@ -133,10 +133,10 @@ class UploadJob:
133133
"""Keeps all the important data about a pending upload job"""
134134

135135
def __init__(
136-
self, version: str, changes: LocalPojectChanges, transaction_id: Optional[str], mp: MerginProject, mc, tmp_dir
136+
self, version: str, changes: LocalProjectChanges, transaction_id: Optional[str], mp: MerginProject, mc, tmp_dir
137137
):
138138
self.version = version
139-
self.changes: LocalPojectChanges = changes # dictionary of local changes to the project
139+
self.changes: LocalProjectChanges = changes # dictionary of local changes to the project
140140
self.transaction_id = transaction_id # ID of the transaction assigned by the server
141141
self.total_size = 0 # size of data to upload (in bytes)
142142
self.transferred_size = 0 # size of data already uploaded (in bytes)
@@ -179,7 +179,7 @@ def update_chunks_from_items(self):
179179
Update chunks in LocalChanges from the upload queue items.
180180
Used just before finalizing the transaction to set the server_chunk_id in v2 API.
181181
"""
182-
self.changes.update_chunks([(item.chunk_id, item.server_chunk_id) for item in self.upload_queue_items])
182+
self.changes.update_chunk_ids([(item.chunk_id, item.server_chunk_id) for item in self.upload_queue_items])
183183

184184

185185
def _do_upload(item: UploadQueueItem, job: UploadJob):
@@ -224,7 +224,7 @@ def create_upload_chunks(mc, mp: MerginProject, local_changes: List[FileChange])
224224

225225

226226
def create_upload_job(
227-
mc, mp: MerginProject, changes: LocalPojectChanges, tmp_dir: tempfile.TemporaryDirectory
227+
mc, mp: MerginProject, changes: LocalProjectChanges, tmp_dir: tempfile.TemporaryDirectory
228228
) -> Optional[UploadJob]:
229229
"""
230230
Prepare transaction and create an upload job for the project using the v1 API.
@@ -317,7 +317,7 @@ def push_project_async(mc, directory) -> Optional[UploadJob]:
317317
if mp.is_versioned_file(f["path"]):
318318
mp.copy_versioned_file_for_upload(f, tmp_dir.name)
319319

320-
local_changes = LocalPojectChanges(
320+
local_changes = LocalProjectChanges(
321321
added=[FileChange(**change) for change in changes["added"]],
322322
updated=[FileChange(**change) for change in changes["updated"]],
323323
removed=[FileChange(**change) for change in changes["removed"]],

mergin/local_changes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass, field
22
from datetime import datetime
3-
from typing import Dict, Optional, List, Tuple
3+
from typing import Optional, List, Tuple
44

55

66
@dataclass
@@ -27,6 +27,7 @@ class FileChange:
2727
chunks: List[str] = field(default_factory=list)
2828
# optional diff information for geopackage files with geodiff metadata
2929
diff: Optional[dict] = None
30+
# File path to be used for reading a file by creating and uploading file in chunks
3031
upload_file: Optional[str] = None
3132
# some functions (MerginProject.compare_file_sets) are adding version to the change from project info
3233
version: Optional[str] = None
@@ -45,6 +46,7 @@ def get_diff(self) -> Optional[FileDiffChange]:
4546
)
4647

4748
def to_server_data(self) -> dict:
49+
"""Convert the FileChange instance to a dictionary format suitable for server payload."""
4850
result = {
4951
"path": self.path,
5052
"checksum": self.checksum,
@@ -61,7 +63,7 @@ def to_server_data(self) -> dict:
6163

6264

6365
@dataclass
64-
class LocalPojectChanges:
66+
class LocalProjectChanges:
6567
added: List[FileChange] = field(default_factory=list)
6668
updated: List[FileChange] = field(default_factory=list)
6769
removed: List[FileChange] = field(default_factory=list)
@@ -93,7 +95,7 @@ def _map_unique_chunks(self, change_chunks: List[str], server_chunks: List[Tuple
9395
seen.add(server_chunk_id)
9496
return mapped
9597

96-
def update_chunks(self, server_chunks: List[Tuple[str, str]]) -> None:
98+
def update_chunk_ids(self, server_chunks: List[Tuple[str, str]]) -> None:
9799
"""
98100
Map chunk ids to chunks returned from server (server_chunk_id).
99101

mergin/test/test_local_changes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from datetime import datetime
22

3-
from ..local_changes import FileChange, LocalPojectChanges
3+
from ..local_changes import FileChange, LocalProjectChanges
44

55

66
def test_local_changes_from_dict():
7-
"""Test generating LocalChanges from a dictionary."""
7+
"""Test generating LocalProjectChanges from a dictionary."""
88
changes_dict = {
99
"added": [{"path": "file1.txt", "checksum": "abc123", "size": 1024, "mtime": datetime.now()}],
1010
"updated": [{"path": "file2.txt", "checksum": "xyz789", "size": 2048, "mtime": datetime.now()}],
@@ -35,7 +35,7 @@ def test_local_changes_from_dict():
3535
updated = [FileChange(**file) for file in changes_dict["updated"]]
3636
removed = [FileChange(**file) for file in changes_dict["removed"]]
3737

38-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
38+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
3939

4040
# Assertions
4141
assert len(local_changes.added) == 1
@@ -72,7 +72,7 @@ def test_local_changes_to_server_payload():
7272
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now())]
7373
removed = [FileChange(path="file3.txt", checksum="lmn456", size=512, mtime=datetime.now())]
7474

75-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
75+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
7676
server_request = local_changes.to_server_payload()
7777

7878
assert "added" in server_request
@@ -83,33 +83,33 @@ def test_local_changes_to_server_payload():
8383
assert server_request["removed"][0]["path"] == "file3.txt"
8484

8585

86-
def test_local_changes_update_chunks():
86+
def test_local_changes_update_chunk_ids():
8787
"""Test the update_chunks method of LocalChanges."""
8888
added = [
8989
FileChange(path="file1.txt", checksum="abc123", size=1024, mtime=datetime.now(), chunks=["abc123"]),
9090
FileChange(path="file2.txt", checksum="abc123", size=1024, mtime=datetime.now(), chunks=["abc123"]),
9191
]
9292
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now(), chunks=["xyz789"])]
9393

94-
local_changes = LocalPojectChanges(added=added, updated=updated)
94+
local_changes = LocalProjectChanges(added=added, updated=updated)
9595
chunks = [("abc123", "chunk1"), ("abc123", "chunk1"), ("xyz789", "chunk2")]
9696

97-
local_changes.update_chunks(chunks)
97+
local_changes.update_chunk_ids(chunks)
9898

9999
assert local_changes.added[0].chunks == ["chunk1"]
100100
assert local_changes.added[1].chunks == ["chunk1"]
101101
assert local_changes.updated[0].chunks == ["chunk2"]
102102

103103

104104
def test_local_changes_get_upload_changes():
105-
"""Test the get_upload_changes method of LocalChanges."""
105+
"""Test the get_upload_changes method of LocalProjectChanges."""
106106
# Create sample LocalChange instances
107107
added = [FileChange(path="file1.txt", checksum="abc123", size=1024, mtime=datetime.now())]
108108
updated = [FileChange(path="file2.txt", checksum="xyz789", size=2048, mtime=datetime.now())]
109109
removed = [FileChange(path="file3.txt", checksum="lmn456", size=512, mtime=datetime.now())]
110110

111111
# Initialize LocalChanges with added, updated, and removed changes
112-
local_changes = LocalPojectChanges(added=added, updated=updated, removed=removed)
112+
local_changes = LocalProjectChanges(added=added, updated=updated, removed=removed)
113113

114114
# Call get_upload_changes
115115
upload_changes = local_changes.get_upload_changes()

0 commit comments

Comments
 (0)