Fix uvx resource packaging issues for OpenRouter functionality
Resolves issues #203, #186, #206, #185 where OpenRouter model registry completely failed to load in uvx installations due to inaccessible conf/custom_models.json file. Changes: - Implement multiple path resolution strategy in OpenRouterModelRegistry - Development: Path(__file__).parent.parent / "conf" / "custom_models.json" - UVX working dir: Path("conf/custom_models.json") - Current working dir: Path.cwd() / "conf" / "custom_models.json" - Add importlib-resources fallback for Python < 3.9 compatibility - Add comprehensive test suite for path resolution scenarios - Ensure graceful handling when config files are missing The fix restores full OpenRouter functionality (15 models, 62+ aliases) for users installing via uvx while maintaining backward compatibility for development and explicit config scenarios. Tested: All path resolution scenarios pass, OpenRouter models load correctly
This commit is contained in:
@@ -37,9 +37,23 @@ class OpenRouterModelRegistry:
|
||||
# Environment variable path
|
||||
self.config_path = Path(env_path)
|
||||
else:
|
||||
# Default to conf/custom_models.json - use relative path from this file
|
||||
# This works in development environment
|
||||
self.config_path = Path(__file__).parent.parent / "conf" / "custom_models.json"
|
||||
# Try multiple potential locations for the config file
|
||||
potential_paths = [
|
||||
Path(__file__).parent.parent / "conf" / "custom_models.json", # Development
|
||||
Path("conf/custom_models.json"), # uvx working directory
|
||||
Path.cwd() / "conf" / "custom_models.json", # Current working directory
|
||||
]
|
||||
|
||||
# Find first existing path
|
||||
self.config_path = None
|
||||
for path in potential_paths:
|
||||
if path.exists():
|
||||
self.config_path = path
|
||||
break
|
||||
|
||||
# If none found, default to the first one for error reporting
|
||||
if self.config_path is None:
|
||||
self.config_path = potential_paths[0]
|
||||
|
||||
# Load configuration
|
||||
self.reload()
|
||||
|
||||
Reference in New Issue
Block a user