From 718d6aad70b4b576fc47eb1b35449c1eaaff7b91 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 17:10:43 +0000 Subject: [PATCH] Add Python detector --- src/docgen/detectors/base.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/docgen/detectors/base.py diff --git a/src/docgen/detectors/base.py b/src/docgen/detectors/base.py new file mode 100644 index 0000000..3857a8d --- /dev/null +++ b/src/docgen/detectors/base.py @@ -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