Merge pull request #604 from mvanhorn/fix/14-mine-no-yaml
fix: allow mining directories without local mempalace.yaml
This commit is contained in:
+21
-5
@@ -264,16 +264,32 @@ def load_config(project_dir: str) -> dict:
|
|||||||
"""Load mempalace.yaml from project directory (falls back to mempal.yaml)."""
|
"""Load mempalace.yaml from project directory (falls back to mempal.yaml)."""
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
config_path = Path(project_dir).expanduser().resolve() / "mempalace.yaml"
|
resolved_project_dir = Path(project_dir).expanduser().resolve()
|
||||||
|
config_path = resolved_project_dir / "mempalace.yaml"
|
||||||
if not config_path.exists():
|
if not config_path.exists():
|
||||||
# Fallback to legacy name
|
# Fallback to legacy name
|
||||||
legacy_path = Path(project_dir).expanduser().resolve() / "mempal.yaml"
|
legacy_path = resolved_project_dir / "mempal.yaml"
|
||||||
if legacy_path.exists():
|
if legacy_path.exists():
|
||||||
config_path = legacy_path
|
config_path = legacy_path
|
||||||
else:
|
else:
|
||||||
print(f"ERROR: No mempalace.yaml found in {project_dir}")
|
wing_name = resolved_project_dir.name
|
||||||
print(f"Run: mempalace init {project_dir}")
|
print(
|
||||||
sys.exit(1)
|
f" No mempalace.yaml found in {resolved_project_dir} "
|
||||||
|
f"— using auto-detected defaults (wing='{wing_name}'). "
|
||||||
|
"Directories with the same basename will share a wing; "
|
||||||
|
"add mempalace.yaml to disambiguate.",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"wing": wing_name,
|
||||||
|
"rooms": [
|
||||||
|
{
|
||||||
|
"name": "general",
|
||||||
|
"description": "All project files",
|
||||||
|
"keywords": ["general"],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
with open(config_path) as f:
|
with open(config_path) as f:
|
||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -6,7 +6,7 @@ from pathlib import Path
|
|||||||
import chromadb
|
import chromadb
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from mempalace.miner import mine, scan_project, status
|
from mempalace.miner import load_config, mine, scan_project, status
|
||||||
from mempalace.palace import NORMALIZE_VERSION, file_already_mined
|
from mempalace.palace import NORMALIZE_VERSION, file_already_mined
|
||||||
|
|
||||||
|
|
||||||
@@ -52,6 +52,20 @@ def test_project_mining():
|
|||||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_config_uses_defaults_when_yaml_missing():
|
||||||
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
|
project_root = Path(tmpdir).resolve()
|
||||||
|
config = load_config(str(project_root))
|
||||||
|
|
||||||
|
assert isinstance(config, dict)
|
||||||
|
assert "wing" in config
|
||||||
|
assert "rooms" in config
|
||||||
|
assert config["wing"] == project_root.name
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def test_scan_project_respects_gitignore():
|
def test_scan_project_respects_gitignore():
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user