Skip to content

Commit 5068214

Browse files
authored
Merge pull request #623 from DagsHub/bug/handling-windows-path-yolo-conversion
bug/handling windows path yolo conversion
2 parents 1e439e9 + fe1988b commit 5068214

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

dagshub/data_engine/annotation/importer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from difflib import SequenceMatcher
2-
from pathlib import Path, PurePosixPath
2+
from pathlib import Path, PurePosixPath, PurePath
33
from tempfile import TemporaryDirectory
44
from typing import TYPE_CHECKING, Literal, Optional, Union, Sequence, Mapping, Callable, List
55

@@ -138,7 +138,7 @@ def remap_annotations(
138138
"""
139139
if remap_func is None:
140140
first_ann = list(annotations.keys())[0]
141-
first_ann_filename = PurePosixPath(first_ann).name
141+
first_ann_filename = Path(first_ann).name
142142
queried = self.ds["path"].endswith(first_ann_filename).select("size").all()
143143
dp_paths = [dp.path for dp in queried]
144144
remap_func = self.guess_annotation_filename_remapping(first_ann, dp_paths)
@@ -185,12 +185,14 @@ def guess_annotation_filename_remapping(
185185

186186
@staticmethod
187187
def generate_path_map_func(ann_path: str, dp_path: str) -> Callable[[str], Optional[str]]:
188-
ann_path_posix = PurePosixPath(ann_path)
188+
# Using os-dependent path for ann_path because we're getting it from the importer,
189+
# which will return os-dependent paths
190+
ann_path_obj = PurePath(ann_path)
189191
dp_path_posix = PurePosixPath(dp_path)
190192

191193
matcher = SequenceMatcher(
192194
None,
193-
ann_path_posix.parts,
195+
ann_path_obj.parts,
194196
dp_path_posix.parts,
195197
)
196198
diff = matcher.get_matching_blocks()
@@ -204,7 +206,7 @@ def generate_path_map_func(ann_path: str, dp_path: str) -> Callable[[str], Optio
204206

205207
match = diff[0]
206208
# Make sure that the match goes until the end
207-
if match.a + match.size != len(ann_path_posix.parts) or match.b + match.size != len(dp_path_posix.parts):
209+
if match.a + match.size != len(ann_path_obj.parts) or match.b + match.size != len(dp_path_posix.parts):
208210
raise CannotRemapPathError(ann_path, dp_path)
209211
# ONE of the paths need to go until the start
210212
if match.a != 0 and match.b != 0:
@@ -214,6 +216,7 @@ def generate_path_map_func(ann_path: str, dp_path: str) -> Callable[[str], Optio
214216
if match.a == 0 and match.b == 0:
215217

216218
def identity_func(x: str) -> str:
219+
# Do a replace because we might be going from a windows path to a posix path
217220
return x.replace(ann_path, dp_path)
218221

219222
return identity_func
@@ -227,17 +230,17 @@ def identity_func(x: str) -> str:
227230
prefix = dp_path_posix.parts[match.a : match.b]
228231

229232
def add_prefix(x: str) -> Optional[str]:
230-
return PurePosixPath(*prefix, x).as_posix()
233+
return PurePath(*prefix, x).as_posix()
231234

232235
return add_prefix
233236

234237
else:
235238
# Remove the prefix
236239
def remove_prefix(x: str) -> Optional[str]:
237-
p = PurePosixPath(x)
240+
p = PurePath(x)
238241
if len(p.parts) <= match.a:
239242
return None
240-
return PurePosixPath(*p.parts[match.a :]).as_posix()
243+
return PurePath(*p.parts[match.a :]).as_posix()
241244

242245
return remove_prefix
243246

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_version(rel_path: str) -> str:
4141
"python-dateutil",
4242
"boto3",
4343
"semver",
44-
"dagshub-annotation-converter>=0.1.5",
44+
"dagshub-annotation-converter>=0.1.12",
4545
]
4646

4747
extras_require = {

0 commit comments

Comments
 (0)