Add source code files (detectors, generators, CLI)

This commit is contained in:
2026-02-01 20:15:30 +00:00
parent b9376397a6
commit 3deed98953

107
src/detectors/ide.py Normal file
View File

@@ -0,0 +1,107 @@
"""IDE detector for identifying development environments."""
from pathlib import Path
from typing import Dict, List
from src.data.patterns import IDE_PATTERNS
from src.detectors.base import BaseDetector
class IDEDetector(BaseDetector):
"""Detects IDEs and editors used in a project."""
def __init__(self) -> None:
self.ide_patterns = IDE_PATTERNS
self.priority = 80
def get_priority(self) -> int:
return self.priority
def detect(self, project_path: Path) -> List[str]:
"""Detect IDEs from project directory.
Args:
project_path: Path to the project directory.
Returns:
List of detected IDE names.
"""
detected_ides = []
for ide, patterns in self.ide_patterns.items():
if self._detect_ide(project_path, ide, patterns):
detected_ides.append(ide)
return detected_ides
def _detect_ide(
self, project_path: Path, ide: str, patterns: List[str]
) -> bool:
"""Check if an IDE is used based on patterns.
Args:
project_path: Project root directory.
ide: IDE name to check.
patterns: List of patterns for the IDE.
Returns:
True if IDE is detected, False otherwise.
"""
for pattern in patterns:
if pattern.startswith("!") or "#" in pattern:
continue
if pattern.endswith("/"):
dir_path = project_path / pattern.rstrip("/")
if dir_path.exists() and dir_path.is_dir():
return True
else:
if pattern.startswith("*"):
for item in project_path.rglob("*"):
if item.is_file() and item.match(pattern):
return True
else:
file_path = project_path / pattern
if file_path.exists():
return True
return False
def detect_vscode(self, project_path: Path) -> bool:
"""Check for VSCode configuration.
Args:
project_path: Path to the project directory.
Returns:
True if VSCode is detected.
"""
vscode_path = project_path / ".vscode"
return vscode_path.exists() and vscode_path.is_dir()
def detect_jetbrains(self, project_path: Path) -> bool:
"""Check for JetBrains IDE configuration.
Args:
project_path: Path to the project directory.
Returns:
True if JetBrains IDE is detected.
"""
idea_path = project_path / ".idea"
return idea_path.exists() and idea_path.is_dir()
def detect_all(self, project_path: Path) -> Dict[str, bool]:
"""Detect all IDEs at once.
Args:
project_path: Path to the project directory.
Returns:
Dict mapping IDE names to detection status.
"""
results = {}
for ide in self.ide_patterns:
results[ide] = self._detect_ide(
project_path, ide, self.ide_patterns[ide]
)
return results