Skip to content

Commit

Permalink
Fixed issue with relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
sevisal committed Sep 29, 2023
1 parent 3d6d783 commit 0124cfc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/vai_lab/_import_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,25 @@ def rel_to_abs(filename: str) -> str:
filename = path.normpath(path.join(get_lib_parent_dir(), filename))
elif filename[0] == "/" or (filename[0].isalpha() and filename[0].isupper()):
filename = filename
return filename
return filename

def abs_to_rel(filename: str) -> str:
"""Checks if path is relative or absolute
If absolute, converts path to relative if possible
If relative, returns itself
"""
if filename[0] == ".":
#Relative path
return filename
elif filename[0].isalpha() and filename[0] != get_lib_parent_dir()[0]:
#Different drive -> Absolute path
return filename
else:
#Same drive not relative
_folder = path.relpath(filename, get_lib_parent_dir())
if _folder[:2] == '..':
# Absolute path
return filename
else:
# Relative path
return path.join('.',_folder)
6 changes: 3 additions & 3 deletions src/vai_lab/utils/plugins/MainPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd

from vai_lab.utils.plugins.dataLoader import dataLoader
from vai_lab._import_helper import get_lib_parent_dir, rel_to_abs
from vai_lab._import_helper import get_lib_parent_dir, abs_to_rel

_PLUGIN_READABLE_NAMES = {"main": "default",
"main page": "alias",
Expand Down Expand Up @@ -311,7 +311,7 @@ def start_dataloader(self):
# Infers by default, should it be None?
data[variable] = pd.read_csv(filename)
isVar[i] = 1
self.controller.xml_handler.append_input_data(variable, rel_to_abs(filename))
self.controller.xml_handler.append_input_data(variable, abs_to_rel(filename))
if i == 0:
self.controller.Data.set(True)
if any(isVar[1::2]) and (
Expand All @@ -337,7 +337,7 @@ def upload_data_path(self):
title='Select a folder',
mustexist=True)
if folder is not None and len(folder) > 0:
self.controller.xml_handler.append_input_data('X', rel_to_abs(folder))
self.controller.xml_handler.append_input_data('X', abs_to_rel(folder))

def upload_data_folder(self):
""" Stores the directory containing the data that will be later loaded
Expand Down

0 comments on commit 0124cfc

Please sign in to comment.