Add Python detector
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-31 17:10:43 +00:00
parent 60807e4388
commit 718d6aad70

View File

@@ -0,0 +1,39 @@
"""Base detector abstract class."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Optional
from docgen.models import Endpoint
if TYPE_CHECKING:
from typing import List
class BaseDetector(ABC):
"""Abstract base class for endpoint detectors."""
extensions: list[str] = []
framework_name: str = ""
@abstractmethod
def detect_endpoints(self, file_path: Path) -> list[Endpoint]:
"""Detect endpoints in a single file."""
pass
def can_detect(self, file_path: Path) -> bool:
"""Check if this detector can handle the given file."""
return any(file_path.suffix == ext for ext in self.extensions)
def scan_directory(self, directory: Path, recursive: bool = True) -> list[Endpoint]:
"""Scan a directory for endpoints."""
endpoints = []
pattern = "**/*" if recursive else "*"
for file_path in directory.glob(pattern):
if file_path.is_file() and self.can_detect(file_path):
try:
endpoints.extend(self.detect_endpoints(file_path))
except Exception:
continue
return endpoints