Skip to content

Commit

Permalink
fix: Update path handling in settings.py for Windows Subsystem for Li…
Browse files Browse the repository at this point in the history
…nux (WSL)
  • Loading branch information
janezlapajne committed Aug 28, 2024
1 parent e323b6a commit 2d4a755
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions source/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from pathlib import Path

from dotenv import load_dotenv
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2d4a755

Please sign in to comment.