Skip to content

Commit 9a8ea4c

Browse files
committed
improve source dir
1 parent 31af680 commit 9a8ea4c

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

cli.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
ENV_FILE = STATE_DIR / ".env"
5050
LOG_FILE = STATE_DIR / "ezlocalai.log"
5151
PID_FILE = STATE_DIR / "ezlocalai.pid"
52+
SOURCE_DIR_FILE = STATE_DIR / "source_dir"
5253
REPO_URL = "https://github.com/DevXT-LLC/ezlocalai.git"
5354
REPO_DIR = STATE_DIR / "repo"
5455

@@ -531,14 +532,33 @@ def is_ezlocalai_folder(folder: Path) -> bool:
531532

532533

533534
def get_ezlocalai_source_dir() -> Optional[Path]:
534-
"""Get the ezlocalai source directory if running from within it.
535+
"""Get the ezlocalai source directory.
535536
536-
Returns the current working directory if it's the ezlocalai folder,
537-
otherwise returns None.
537+
Checks (in order):
538+
1. Current working directory (if it's the ezlocalai folder)
539+
2. Persisted source directory from ~/.ezlocalai/source_dir
540+
541+
When found via cwd, the path is persisted so future invocations
542+
from other directories still find the source .env and compose files.
538543
"""
539544
cwd = Path.cwd()
540545
if is_ezlocalai_folder(cwd):
546+
# Persist for future use from other directories
547+
try:
548+
SOURCE_DIR_FILE.write_text(str(cwd), encoding="utf-8")
549+
except OSError:
550+
pass
541551
return cwd
552+
553+
# Check persisted path
554+
if SOURCE_DIR_FILE.exists():
555+
try:
556+
saved = Path(SOURCE_DIR_FILE.read_text(encoding="utf-8").strip())
557+
if saved.exists() and is_ezlocalai_folder(saved):
558+
return saved
559+
except (OSError, ValueError):
560+
pass
561+
542562
return None
543563

544564

0 commit comments

Comments
 (0)