This commit is contained in:
39
src/docgen/detectors/base.py
Normal file
39
src/docgen/detectors/base.py
Normal 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
|
||||||
Reference in New Issue
Block a user