Skip to content

Commit 8ee65b2

Browse files
committed
Add assertions for file attributes and improve imports
Added assertions to ensure required file attributes (file_id, file_name) are present and of correct type in dvuploader.py and packaging.py. Also reorganized import statements for consistency and readability.
1 parent b32947b commit 8ee65b2

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

dvuploader/dvuploader.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import asyncio
2-
from urllib.parse import urljoin
3-
import httpx
42
import os
5-
import rich
63
from typing import Dict, List, Optional
4+
from urllib.parse import urljoin
75

6+
import httpx
7+
import rich
88
from pydantic import BaseModel
9-
from rich.progress import Progress
10-
from rich.table import Table
119
from rich.console import Console
1210
from rich.panel import Panel
11+
from rich.progress import Progress
12+
from rich.table import Table
1313

1414
from dvuploader.directupload import (
1515
TICKET_ENDPOINT,
@@ -239,7 +239,13 @@ def _check_duplicates(
239239
to_skip.append(file.file_id)
240240

241241
if replace_existing:
242+
assert file.file_id is not None, "File ID is required"
243+
assert isinstance(file.file_id, int), "File ID must be an integer"
244+
242245
ds_file = self._get_dsfile_by_id(file.file_id, ds_files)
246+
247+
assert ds_file is not None, "Dataset file not found"
248+
243249
if not self._check_size(file, ds_file):
244250
file._unchanged_data = False
245251
else:
@@ -359,10 +365,12 @@ def _check_hashes(file: File, dsFile: Dict):
359365
dsFile.get("directoryLabel", ""), dsFile["dataFile"]["filename"]
360366
)
361367

368+
directory_label = file.directory_label if file.directory_label else ""
369+
362370
return (
363371
file.checksum.value == hash_value
364372
and file.checksum.type == hash_algo
365-
and path == os.path.join(file.directory_label, file.file_name) # type: ignore
373+
and path == os.path.join(directory_label, file.file_name) # type: ignore
366374
)
367375

368376
@staticmethod

dvuploader/packaging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import zipfile
3-
43
from typing import List, Tuple
4+
55
from dvuploader.file import File
66

77
MAXIMUM_PACKAGE_SIZE = int(
@@ -117,4 +117,5 @@ def _create_arcname(file: File) -> str:
117117
if file.directory_label is not None:
118118
return os.path.join(file.directory_label, file.file_name) # type: ignore
119119
else:
120+
assert file.file_name is not None, "File name is required"
120121
return file.file_name

0 commit comments

Comments
 (0)