Skip to content

Commit 76a1550

Browse files
authored
Merge pull request #2 from contextforge-org/FixHomeDirCreation
fix: Create the home dir if it doesn't exist
2 parents 92c68f5 + 9381bb4 commit 76a1550

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

cforge/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def get_settings() -> CLISettings:
7171
# NOTE: This duplicates the source of truth for the env var slightly so that
7272
# we can use home as the source for the .env file as a 2-phase init.
7373
home = Path(os.getenv("CONTEXTFORGE_HOME", DEFAULT_HOME))
74+
home.mkdir(exist_ok=True)
7475
with _chdir(home):
7576

7677
settings = CLISettings(client_mode=True)

tests/test_config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
77
Tests for configuration management.
88
"""
9+
# Standard
10+
from pathlib import Path
11+
from unittest import mock
12+
import os
13+
import tempfile
914

1015
# First-Party
1116
from cforge.config import get_settings
@@ -27,3 +32,17 @@ def test_get_settings_singleton(self) -> None:
2732
settings1 = get_settings()
2833
settings2 = get_settings()
2934
assert settings1 is settings2
35+
36+
def test_get_settings_make_home(self) -> None:
37+
"""Test that get_settings will create the home dir if needed"""
38+
try:
39+
get_settings.cache_clear()
40+
with tempfile.TemporaryDirectory() as work_dir:
41+
home_dir = Path(work_dir) / "some_new_home"
42+
assert not home_dir.exists()
43+
with mock.patch.dict(os.environ, {"CONTEXTFORGE_HOME": str(home_dir)}):
44+
settings = get_settings()
45+
assert settings.contextforge_home == home_dir
46+
assert home_dir.exists()
47+
finally:
48+
get_settings.cache_clear()

0 commit comments

Comments
 (0)