Initial commit: CodeMap v0.1.0 - CLI tool for code analysis and diagram generation
This commit is contained in:
39
codemap/parsers/base.py
Normal file
39
codemap/parsers/base.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Set
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Dependency:
|
||||||
|
module_name: str
|
||||||
|
file_path: Path
|
||||||
|
line_number: int
|
||||||
|
alias: str = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ParsedFile:
|
||||||
|
file_path: Path
|
||||||
|
module_name: str
|
||||||
|
dependencies: List[Dependency]
|
||||||
|
file_type: str
|
||||||
|
|
||||||
|
|
||||||
|
class BaseParser(ABC):
|
||||||
|
supported_extensions: List[str] = []
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def parse(self, file_path: Path) -> ParsedFile:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def extract_module_name(self, file_path: Path) -> str:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def can_parse(self, file_path: Path) -> bool:
|
||||||
|
return file_path.suffix in self.supported_extensions
|
||||||
|
|
||||||
|
def _clean_import_name(self, import_str: str) -> str:
|
||||||
|
parts = import_str.split(".")
|
||||||
|
return parts[0]
|
||||||
Reference in New Issue
Block a user