Spaces:
Build error
Build error
File size: 826 Bytes
4fa8bcb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import os
import tempfile
def resolve_path(filename: str, subdir: str = "", write_mode: bool = False):
tmp_root = tempfile.gettempdir()
tmp_path = os.path.normpath(os.path.join(tmp_root, subdir, filename))
repo_path = os.path.normpath(os.path.join("data", subdir, filename))
# Debug
print(f"๐ Checking temp path: {tmp_path} (exists={os.path.isfile(tmp_path)})")
print(f"๐ Checking data path: {repo_path} (exists={os.path.isfile(repo_path)})")
if write_mode:
os.makedirs(os.path.dirname(tmp_path), exist_ok=True)
return tmp_path
if os.path.isfile(tmp_path):
return tmp_path
if os.path.isfile(repo_path):
return repo_path
raise FileNotFoundError(
f"File not found in either path:\n - temp: {tmp_path}\n - fallback: {repo_path}"
)
|