Skip to content

Commit d9ad8b6

Browse files
authored
Path logic fixes for MSYS2 Windows-style paths (#517)
* Replaced Path().resolve() with Path().absolute() in client-side modules * Fixed path logic in '_xml_file' function and '_grid_square_metadata_file'; added catch to _analyse for ValueError
1 parent ab2961f commit d9ad8b6

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

src/murfey/client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def run():
239239

240240
if args.remove_files:
241241
remove_prompt = Confirm.ask(
242-
f"Are you sure you want to remove files from {args.source or Path('.').resolve()}?"
242+
f"Are you sure you want to remove files from {args.source or Path('.').absolute()}?"
243243
)
244244
if not remove_prompt:
245245
exit("Exiting")

src/murfey/client/analyser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def _analyse(self):
302302
f"Metadata gathering failed with a key error for key: {e.args[0]}"
303303
)
304304
raise e
305+
except ValueError as e:
306+
logger.error(
307+
f"Metadata gathering failed with a value error: {e}"
308+
)
305309
if not dc_metadata or not self._force_mdoc_metadata:
306310
self._unseen_xml.append(transferred_file)
307311
else:
@@ -406,16 +410,16 @@ def _xml_file(self, data_file: Path) -> Path:
406410
data_directories = self._murfey_config.get("data_directories", [])
407411
for dd in data_directories:
408412
if str(data_file).startswith(dd):
409-
base_dir = Path(dd)
410-
mid_dir = data_file.relative_to(dd).parent
413+
base_dir = Path(dd).absolute()
414+
mid_dir = data_file.relative_to(base_dir).parent
411415
break
412416
else:
413417
return data_file.with_suffix(".xml")
414418
return base_dir / self._environment.visit / mid_dir / file_name
415419

416420
def enqueue(self, rsyncer: RSyncerUpdate):
417421
if not self._stopping and rsyncer.outcome == TransferResult.SUCCESS:
418-
absolute_path = (self._basepath / rsyncer.file_path).resolve()
422+
absolute_path = (self._basepath / rsyncer.file_path).absolute()
419423
self.queue.put(absolute_path)
420424

421425
def start(self):

src/murfey/client/contexts/spa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def _grid_square_metadata_file(
6161
) -> Path:
6262
for dd in data_directories:
6363
if str(f).startswith(str(dd)):
64-
base_dir = dd
65-
mid_dir = f.relative_to(dd).parent
64+
base_dir = dd.absolute()
65+
mid_dir = f.relative_to(base_dir).parent
6666
break
6767
else:
6868
raise ValueError(f"Could not determine grid square metadata path for {f}")

src/murfey/client/rsync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def finalise(self, thread: bool = True):
199199

200200
def enqueue(self, file_path: Path):
201201
if not self._stopping:
202-
absolute_path = (self._basepath / file_path).resolve()
202+
absolute_path = self._basepath / file_path
203203
self.queue.put(absolute_path)
204204

205205
def _process(self):

src/murfey/client/tui/screens.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def determine_default_destination(
8888
_default = ""
8989
if environment.processing_only_mode and environment.sources:
9090
log.info(f"Processing only mode with sources {environment.sources}")
91-
_default = str(environment.sources[0].resolve()) or str(Path.cwd())
91+
_default = str(environment.sources[0].absolute()) or str(Path.cwd())
9292
elif machine_data.get("data_directories"):
9393
for data_dir in machine_data["data_directories"]:
94-
if source.resolve() == Path(data_dir):
94+
if source.absolute() == Path(data_dir).absolute():
9595
_default = f"{destination}/{visit}"
9696
break
9797
else:
9898
try:
99-
mid_path = source.resolve().relative_to(data_dir)
99+
mid_path = source.absolute().relative_to(Path(data_dir).absolute())
100100
if use_suggested_path:
101101
with global_env_lock:
102102
source_name = (
@@ -221,7 +221,7 @@ def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
221221
self.valid_selection = True
222222
return
223223
for d in self._data_directories:
224-
if Path(self._selected_path).resolve().is_relative_to(d):
224+
if Path(self._selected_path).absolute().is_relative_to(d.absolute()):
225225
self.valid_selection = True
226226
break
227227
else:
@@ -282,7 +282,9 @@ def compose(self):
282282
btn_disabled = True
283283
for d in machine_data.get("data_directories", []):
284284
if (
285-
Path(self._dir_tree._selected_path).resolve().is_relative_to(d)
285+
Path(self._dir_tree._selected_path)
286+
.absolute()
287+
.is_relative_to(Path(d).absolute())
286288
or self.app._environment.processing_only_mode
287289
):
288290
btn_disabled = False
@@ -306,7 +308,7 @@ def _check_valid_selection(self, valid: bool):
306308
self._add_btn.disabled = True
307309

308310
def _add_directory(self, directory: str, add_destination: bool = True):
309-
source = Path(self._dir_tree.path).resolve() / directory
311+
source = Path(self._dir_tree.path).absolute() / directory
310312
if add_destination:
311313
for s in self.app._environment.sources:
312314
if source.is_relative_to(s):
@@ -705,9 +707,9 @@ def on_button_pressed(self, event: Button.Pressed):
705707
self.app.install_screen(
706708
DirectorySelection(
707709
[
708-
p
709-
for p in machine_data.get("data_directories", [])
710-
if Path(p).exists()
710+
path
711+
for path in machine_data.get("data_directories", [])
712+
if Path(path).exists()
711713
]
712714
),
713715
"directory-select",
@@ -771,9 +773,9 @@ def on_button_pressed(self, event: Button.Pressed):
771773
self.app.install_screen(
772774
DirectorySelection(
773775
[
774-
p
775-
for p in machine_data.get("data_directories", [])
776-
if Path(p).exists()
776+
path
777+
for path in machine_data.get("data_directories", [])
778+
if Path(path).exists()
777779
]
778780
),
779781
"directory-select",
@@ -941,7 +943,7 @@ def __init__(self, directories: List[str], *args, **kwargs):
941943

942944
def on_button_pressed(self, event: Button.Pressed):
943945
self.app._multigrid = self._switch_status
944-
visit_dir = Path(str(event.button.label)) / self.app._visit
946+
visit_dir = Path(str(event.button.label)).absolute() / self.app._visit
945947
visit_dir.mkdir(exist_ok=True)
946948
self.app._set_default_acquisition_directories(visit_dir)
947949
machine_config = get_machine_config_client(

0 commit comments

Comments
 (0)