Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Consiliency_treesitter-chunker /chunker /interfaces /stubs.py
| """Stub implementations of interfaces for testing. | |
| These are minimal implementations that raise NotImplementedError | |
| for all methods. Worktrees can import these for testing their | |
| code before the actual implementations are available. | |
| """ | |
| import io | |
| from pathlib import Path | |
| from re import Pattern | |
| from typing import Any | |
| from tree_sitter import Node | |
| from chunker.types import CodeChunk | |
| from .base import ASTProcessor, ChunkingStrategy | |
| from .context import ContextExtractor, ContextItem | |
| from .debug import ASTVisualizer | |
| from .export import ChunkRelationship, ExportFormat, StructuredExporter | |
| from .fallback import FallbackChunker | |
| from .grammar import GrammarManager | |
| from .performance import CacheManager | |
| from .query import Query, QueryEngine, QueryMatch | |
| class ChunkingStrategyStub(ChunkingStrategy): | |
| """Stub implementation of ChunkingStrategy.""" | |
| def can_handle(file_path: str, language: str) -> bool: | |
| raise NotImplementedError("ChunkingStrategyStub.can_handle not implemented") | |
| def chunk( | |
| ast: Node, | |
| source: bytes, | |
| file_path: str, | |
| language: str, | |
| ) -> list[CodeChunk]: | |
| raise NotImplementedError("ChunkingStrategyStub.chunk not implemented") | |
| def configure(config: dict[str, Any]) -> None: | |
| raise NotImplementedError("ChunkingStrategyStub.configure not implemented") | |
| class ASTProcessorStub(ASTProcessor): | |
| """Stub implementation of ASTProcessor.""" | |
| def process_node(node: Node, context: dict[str, Any]) -> Any: | |
| raise NotImplementedError("ASTProcessorStub.process_node not implemented") | |
| def should_process_children(node: Node, context: dict[str, Any]) -> bool: | |
| raise NotImplementedError( | |
| "ASTProcessorStub.should_process_children not implemented", | |
| ) | |
| class QueryStub(Query): | |
| """Stub implementation of Query.""" | |
| def pattern_count() -> int: | |
| raise NotImplementedError("QueryStub.pattern_count not implemented") | |
| def capture_names() -> list[str]: | |
| raise NotImplementedError("QueryStub.capture_names not implemented") | |
| def disable_pattern(pattern_index: int) -> None: | |
| raise NotImplementedError("QueryStub.disable_pattern not implemented") | |
| def is_pattern_enabled(pattern_index: int) -> bool: | |
| raise NotImplementedError("QueryStub.is_pattern_enabled not implemented") | |
| class QueryEngineStub(QueryEngine): | |
| """Stub implementation of QueryEngine.""" | |
| def parse_query(query_string: str, language: str) -> Query: | |
| raise NotImplementedError( | |
| "QueryEngineStub.parse_query not implemented", | |
| ) | |
| def execute_query(ast: Node, query: Query) -> list[QueryMatch]: | |
| raise NotImplementedError("QueryEngineStub.execute_query not implemented") | |
| def validate_query(query_string: str, language: str) -> tuple[bool, str | None]: | |
| raise NotImplementedError("QueryEngineStub.validate_query not implemented") | |
| class ContextExtractorStub(ContextExtractor): | |
| """Stub implementation of ContextExtractor.""" | |
| def extract_imports(ast: Node, source: bytes) -> list[ContextItem]: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.extract_imports not implemented", | |
| ) | |
| def extract_type_definitions(ast: Node, source: bytes) -> list[ContextItem]: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.extract_type_definitions not implemented", | |
| ) | |
| def extract_dependencies(node: Node, ast: Node, source: bytes) -> list[ContextItem]: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.extract_dependencies not implemented", | |
| ) | |
| def extract_parent_context( | |
| node: Node, | |
| ast: Node, | |
| source: bytes, | |
| ) -> list[ContextItem]: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.extract_parent_context not implemented", | |
| ) | |
| def find_decorators(node: Node, source: bytes) -> list[ContextItem]: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.find_decorators not implemented", | |
| ) | |
| def build_context_prefix( | |
| context_items: list[ContextItem], | |
| max_size: int | None = None, | |
| ) -> str: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.build_context_prefix not implemented", | |
| ) | |
| def process_node(node: Node, context: dict[str, Any]) -> Any: | |
| raise NotImplementedError("ContextExtractorStub.process_node not implemented") | |
| def should_process_children(node: Node, context: dict[str, Any]) -> bool: | |
| raise NotImplementedError( | |
| "ContextExtractorStub.should_process_children not implemented", | |
| ) | |
| class CacheManagerStub(CacheManager): | |
| """Stub implementation of CacheManager.""" | |
| def get(key: str) -> Any | None: | |
| raise NotImplementedError("CacheManagerStub.get not implemented") | |
| def put(key: str, value: Any, ttl_seconds: int | None = None) -> None: | |
| raise NotImplementedError("CacheManagerStub.put not implemented") | |
| def invalidate(key: str) -> bool: | |
| raise NotImplementedError( | |
| "CacheManagerStub.invalidate not implemented", | |
| ) | |
| def invalidate_pattern(pattern: str) -> int: | |
| raise NotImplementedError("CacheManagerStub.invalidate_pattern not implemented") | |
| def clear() -> None: | |
| raise NotImplementedError("CacheManagerStub.clear not implemented") | |
| def size() -> int: | |
| raise NotImplementedError("CacheManagerStub.size not implemented") | |
| def memory_usage() -> int: | |
| raise NotImplementedError("CacheManagerStub.memory_usage not implemented") | |
| def evict_expired() -> int: | |
| raise NotImplementedError("CacheManagerStub.evict_expired not implemented") | |
| def get_stats() -> dict[str, Any]: | |
| raise NotImplementedError("CacheManagerStub.get_stats not implemented") | |
| class StructuredExporterStub(StructuredExporter): | |
| """Stub implementation of StructuredExporter.""" | |
| def export( | |
| chunks: list[CodeChunk], | |
| relationships: list[ChunkRelationship], | |
| output: Path | io.IOBase, | |
| metadata: Any | None = None, | |
| ) -> None: | |
| raise NotImplementedError("StructuredExporterStub.export not implemented") | |
| def export_streaming( | |
| chunk_iterator: Any, | |
| relationship_iterator: Any, | |
| output: Path | io.IOBase, | |
| ) -> None: | |
| raise NotImplementedError( | |
| "StructuredExporterStub.export_streaming not implemented", | |
| ) | |
| def supports_format(fmt: ExportFormat) -> bool: | |
| raise NotImplementedError( | |
| "StructuredExporterStub.supports_format not implemented", | |
| ) | |
| def get_schema() -> dict[str, Any]: | |
| raise NotImplementedError("StructuredExporterStub.get_schema not implemented") | |
| class GrammarManagerStub(GrammarManager): | |
| """Stub implementation of GrammarManager.""" | |
| def add_grammar( | |
| name: str, | |
| repository_url: str, | |
| commit_hash: str | None = None, | |
| ) -> Any: | |
| raise NotImplementedError("GrammarManagerStub.add_grammar not implemented") | |
| def fetch_grammar(name: str) -> bool: | |
| raise NotImplementedError("GrammarManagerStub.fetch_grammar not implemented") | |
| def build_grammar(name: str) -> bool: | |
| raise NotImplementedError("GrammarManagerStub.build_grammar not implemented") | |
| def get_grammar_info(name: str) -> Any | None: | |
| raise NotImplementedError("GrammarManagerStub.get_grammar_info not implemented") | |
| def list_grammars(status: Any | None = None) -> list[Any]: | |
| raise NotImplementedError("GrammarManagerStub.list_grammars not implemented") | |
| def update_grammar(name: str) -> bool: | |
| raise NotImplementedError("GrammarManagerStub.update_grammar not implemented") | |
| def remove_grammar(name: str) -> bool: | |
| raise NotImplementedError("GrammarManagerStub.remove_grammar not implemented") | |
| def get_node_types(language: str) -> list[Any]: | |
| raise NotImplementedError("GrammarManagerStub.get_node_types not implemented") | |
| def validate_grammar(name: str) -> tuple[bool, str | None]: | |
| raise NotImplementedError("GrammarManagerStub.validate_grammar not implemented") | |
| class FallbackChunkerStub(FallbackChunker): | |
| """Stub implementation of FallbackChunker.""" | |
| def can_handle(file_path: str, language: str) -> bool: | |
| raise NotImplementedError("FallbackChunkerStub.can_handle not implemented") | |
| def chunk( | |
| ast: Node, | |
| source: bytes, | |
| file_path: str, | |
| language: str, | |
| ) -> list[CodeChunk]: | |
| raise NotImplementedError("FallbackChunkerStub.chunk not implemented") | |
| def configure(config: dict[str, Any]) -> None: | |
| raise NotImplementedError("FallbackChunkerStub.configure not implemented") | |
| def set_fallback_reason(reason: Any) -> None: | |
| raise NotImplementedError( | |
| "FallbackChunkerStub.set_fallback_reason not implemented", | |
| ) | |
| def chunk_by_lines( | |
| content: str, | |
| lines_per_chunk: int, | |
| overlap_lines: int = 0, | |
| ) -> list[CodeChunk]: | |
| raise NotImplementedError("FallbackChunkerStub.chunk_by_lines not implemented") | |
| def chunk_by_delimiter( | |
| content: str, | |
| delimiter: str, | |
| include_delimiter: bool = True, | |
| ) -> list[CodeChunk]: | |
| raise NotImplementedError( | |
| "FallbackChunkerStub.chunk_by_delimiter not implemented", | |
| ) | |
| def chunk_by_pattern( | |
| content: str, | |
| pattern: Pattern, | |
| include_match: bool = True, | |
| ) -> list[CodeChunk]: | |
| raise NotImplementedError( | |
| "FallbackChunkerStub.chunk_by_pattern not implemented", | |
| ) | |
| def emit_warning() -> str: | |
| raise NotImplementedError("FallbackChunkerStub.emit_warning not implemented") | |
| class ASTVisualizerStub(ASTVisualizer): | |
| """Stub implementation of ASTVisualizer.""" | |
| def visualize(node: Node, source: bytes, fmt: Any = None) -> str: | |
| raise NotImplementedError( | |
| "ASTVisualizerStub.visualize not implemented", | |
| ) | |
| def visualize_with_chunks( | |
| node: Node, | |
| source: bytes, | |
| chunks: list[CodeChunk], | |
| fmt: Any = None, | |
| ) -> str: | |
| raise NotImplementedError( | |
| "ASTVisualizerStub.visualize_with_chunks not implemented", | |
| ) | |
| def highlight_nodes(nodes: list[Node], style: Any) -> None: | |
| raise NotImplementedError("ASTVisualizerStub.highlight_nodes not implemented") | |
| def set_max_depth(depth: int) -> None: | |
| raise NotImplementedError("ASTVisualizerStub.set_max_depth not implemented") | |
| def set_node_filter(filter_func: Any) -> None: | |
| raise NotImplementedError("ASTVisualizerStub.set_node_filter not implemented") | |
| def export_interactive(output_path: str) -> None: | |
| raise NotImplementedError( | |
| "ASTVisualizerStub.export_interactive not implemented", | |
| ) | |
| __all__ = [ | |
| "ASTProcessorStub", | |
| "ASTVisualizerStub", | |
| "CacheManagerStub", | |
| "ChunkingStrategyStub", | |
| "ContextExtractorStub", | |
| "FallbackChunkerStub", | |
| "GrammarManagerStub", | |
| "QueryEngineStub", | |
| "QueryStub", | |
| "StructuredExporterStub", | |
| ] | |
Xet Storage Details
- Size:
- 12.1 kB
- Xet hash:
- 6f919277baa1075f59b88213048fed8c65b1b3e1085e13c7c98ebfb1384a58b0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.