From 2d4a755607c2e17a9f50ebd49372e6a708a30f21 Mon Sep 17 00:00:00 2001 From: janezlapajne Date: Thu, 29 Aug 2024 00:35:01 +0200 Subject: [PATCH] fix: Update path handling in settings.py for Windows Subsystem for Linux (WSL) --- source/core/settings.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/core/settings.py b/source/core/settings.py index 4f13d6d..e387bad 100644 --- a/source/core/settings.py +++ b/source/core/settings.py @@ -1,3 +1,4 @@ +import re from pathlib import Path from dotenv import load_dotenv @@ -48,8 +49,12 @@ class Settings(BaseSettings): def correct_path(cls, path: str | Path): if path is None: raise ValueError("Define 'IMAGES_DIR' in .env file.") - if ":\\" in str(path): - path = str(path).replace("F:\\", "/mnt/f/").replace("\\", "/") + path = str(path) + # If the os is run as wsl (windows subsystem for linux) + if ":\\" in path: + path = re.sub( + r"([A-Za-z]):\\", lambda m: f"/mnt/{m.group(1).lower()}/", path + ).replace("\\", "/") if path.startswith('r"') and path.endswith('"'): path = path[2:-1] path = Path(path)