mirror of
https://github.com/sanjeed5/awesome-cursor-rules-mdc.git
synced 2026-11-30 14:52:55 +08:00
Enhance rules.json loading with improved path resolution and logging
- Refactor load_library_data to prioritize specified rules.json path - Add detailed logging for rules.json discovery and loading process - Improve error handling and path resolution for rules.json - Provide more informative debug and warning messages during library data loading
This commit is contained in:
@@ -502,27 +502,36 @@ def load_library_data(rules_path: Optional[str] = None) -> Dict[str, Any]:
|
|||||||
Returns:
|
Returns:
|
||||||
Dictionary of library data
|
Dictionary of library data
|
||||||
"""
|
"""
|
||||||
if not rules_path:
|
# If a specific path is provided, use it first
|
||||||
|
if rules_path and Path(rules_path).exists():
|
||||||
|
logger.debug(f"Using specified rules.json at {rules_path}")
|
||||||
|
path_to_use = Path(rules_path)
|
||||||
|
else:
|
||||||
|
# Search for rules.json in priority order
|
||||||
possible_paths = [
|
possible_paths = [
|
||||||
Path(__file__).parent / "rules.json",
|
Path(__file__).parent / "rules.json", # src/rules.json
|
||||||
Path(__file__).parent.parent / "rules.json",
|
Path(__file__).parent.parent / "rules.json", # package root rules.json
|
||||||
Path.cwd() / "rules.json"
|
Path.cwd() / "rules.json" # current directory rules.json
|
||||||
]
|
]
|
||||||
|
|
||||||
|
path_to_use = None
|
||||||
for path in possible_paths:
|
for path in possible_paths:
|
||||||
if path.exists():
|
if path.exists():
|
||||||
rules_path = str(path)
|
path_to_use = path
|
||||||
|
logger.debug(f"Found rules.json at {path}")
|
||||||
break
|
break
|
||||||
|
|
||||||
if not rules_path or not Path(rules_path).exists():
|
if not path_to_use or not path_to_use.exists():
|
||||||
logger.warning("rules.json not found, using default library detection")
|
logger.warning("rules.json not found in any standard location, using default library detection")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(rules_path, 'r') as f:
|
with open(path_to_use, 'r') as f:
|
||||||
return json.load(f)
|
data = json.load(f)
|
||||||
|
logger.info(f"Successfully loaded rules.json from {path_to_use}")
|
||||||
|
return data
|
||||||
except (json.JSONDecodeError, IOError) as e:
|
except (json.JSONDecodeError, IOError) as e:
|
||||||
logger.warning(f"Error loading rules.json: {e}")
|
logger.warning(f"Error loading rules.json from {path_to_use}: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def normalize_library_name(name: str, library_data: Dict[str, Any]) -> str:
|
def normalize_library_name(name: str, library_data: Dict[str, Any]) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user