Detect supported programming languages in a directory. Args: directory: Directory to scan Returns: List of (language, file_count) tuples
(directory: Path)
| 154 | |
| 155 | |
| 156 | def detect_supported_languages(directory: Path) -> List[Tuple[str, int]]: |
| 157 | """ |
| 158 | Detect supported programming languages in a directory. |
| 159 | |
| 160 | Args: |
| 161 | directory: Directory to scan |
| 162 | |
| 163 | Returns: |
| 164 | List of (language, file_count) tuples |
| 165 | """ |
| 166 | language_extensions = { |
| 167 | 'Python': ['.py'], |
| 168 | 'Java': ['.java'], |
| 169 | 'JavaScript': ['.js', '.jsx'], |
| 170 | 'TypeScript': ['.ts', '.tsx'], |
| 171 | 'C': ['.c', '.h'], |
| 172 | 'C++': ['.cpp', '.hpp', '.cc', '.hh', '.cxx', '.hxx'], |
| 173 | 'C#': ['.cs'], |
| 174 | 'PHP': ['.php', '.phtml', '.inc'], |
| 175 | 'Kotlin': ['.kt', '.kts'], |
| 176 | } |
| 177 | |
| 178 | # Directories to exclude from counting |
| 179 | excluded_dirs = { |
| 180 | 'node_modules', '__pycache__', '.git', 'build', 'dist', |
| 181 | '.venv', 'venv', 'env', '.env', 'target', 'bin', 'obj', |
| 182 | '.pytest_cache', '.mypy_cache', '.tox', 'coverage', |
| 183 | 'htmlcov', '.eggs', '*.egg-info', 'vendor', 'bower_components', |
| 184 | '.idea', '.vscode', '.gradle', '.mvn' |
| 185 | } |
| 186 | |
| 187 | def should_exclude_file(file_path: Path) -> bool: |
| 188 | """Check if file is in an excluded directory.""" |
| 189 | parts = file_path.parts |
| 190 | return any(excluded_dir in parts for excluded_dir in excluded_dirs) |
| 191 | |
| 192 | language_counts = {} |
| 193 | |
| 194 | for language, extensions in language_extensions.items(): |
| 195 | count = 0 |
| 196 | for ext in extensions: |
| 197 | # Filter out files in excluded directories |
| 198 | count += sum( |
| 199 | 1 for f in directory.rglob(f"*{ext}") |
| 200 | if f.is_file() and not should_exclude_file(f) |
| 201 | ) |
| 202 | |
| 203 | if count > 0: |
| 204 | language_counts[language] = count |
| 205 | |
| 206 | # Sort by count descending |
| 207 | return sorted(language_counts.items(), key=lambda x: x[1], reverse=True) |
| 208 | |
| 209 | |
| 210 | def is_top_tier_model(model: str) -> bool: |
no test coverage detected