Skip to content

Commit 85c086c

Browse files
committed
fix: support PackageLoader in metaspec sync command
Issue: sync command failed with 'Unexpected loader type' when MetaSpec was installed in editable mode (pip install -e .). Root Cause: - Code only checked for FileSystemLoader - Generator uses PackageLoader in editable installs - PackageLoader doesn't have searchpath attribute Solution: - Support both FileSystemLoader and PackageLoader - Use metaspec.__file__ to locate templates for PackageLoader - Add template directory existence check - Improve error messages Impact: - ✅ Works with: pip install metaspec - ✅ Works with: pip install -e . (development mode) - ✅ Works with: uv pip install -e . Resolves the bug reported in user feedback.
1 parent 34df9fa commit 85c086c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/metaspec/cli/sync.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,24 @@ def sync_command(
114114

115115
# Step 6: Get new commands from installed MetaSpec
116116
try:
117-
from jinja2 import FileSystemLoader
117+
from jinja2 import FileSystemLoader, PackageLoader
118118

119+
import metaspec
119120
from metaspec.generator import Generator
120121
gen = Generator()
121-
if not isinstance(gen.env.loader, FileSystemLoader):
122-
raise RuntimeError("Unexpected loader type")
123-
template_dir = Path(gen.env.loader.searchpath[0]) / "meta"
122+
123+
# Support both FileSystemLoader and PackageLoader
124+
if isinstance(gen.env.loader, FileSystemLoader):
125+
template_dir = Path(gen.env.loader.searchpath[0]) / "meta"
126+
elif isinstance(gen.env.loader, PackageLoader):
127+
# Use package location for editable installs
128+
template_dir = Path(metaspec.__file__).parent / "templates" / "meta"
129+
else:
130+
raise RuntimeError(f"Unsupported loader type: {type(gen.env.loader)}")
131+
132+
if not template_dir.exists():
133+
raise RuntimeError(f"Template directory not found: {template_dir}")
134+
124135
except Exception as e:
125136
console.print(
126137
"[red]Error:[/red] Could not locate MetaSpec templates: " + str(e),

0 commit comments

Comments
 (0)