Coverage for lintro / plugins / __init__.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Lintro plugin system. 

2 

3This package provides the plugin architecture for Lintro, enabling both 

4built-in tools and external plugins to be registered and discovered. 

5 

6Core Components: 

7 - LintroPlugin: Protocol defining the tool interface 

8 - ToolDefinition: Dataclass for tool metadata 

9 - ToolRegistry: Central registry for tool registration 

10 - BaseToolPlugin: Base class for implementing tools 

11 - register_tool: Decorator for registering tools 

12 

13Example: 

14 Creating a custom tool plugin: 

15 

16 >>> from lintro.plugins import ToolDefinition, register_tool 

17 >>> from lintro.plugins.base import BaseToolPlugin 

18 >>> from lintro.enums.tool_type import ToolType 

19 >>> from lintro.models.core.tool_result import ToolResult 

20 >>> 

21 >>> @register_tool 

22 ... class MyPlugin(BaseToolPlugin): 

23 ... @property 

24 ... def definition(self) -> ToolDefinition: 

25 ... return ToolDefinition( 

26 ... name="my-tool", 

27 ... description="My custom linting tool", 

28 ... tool_type=ToolType.LINTER, 

29 ... file_patterns=["*.py"], 

30 ... ) 

31 ... 

32 ... def check(self, paths: list[str], options: dict[str, object]) -> ToolResult: 

33 ... # Implementation here 

34 ... return ToolResult(name="my-tool", success=True, issues_count=0) 

35 

36 Using the registry: 

37 

38 >>> from lintro.plugins import ToolRegistry 

39 >>> from lintro.plugins.discovery import discover_all_tools 

40 >>> 

41 >>> discover_all_tools() # Load all available tools 

42 >>> tool = ToolRegistry.get("my-tool") 

43 >>> result = tool.check(["."], {}) 

44""" 

45 

46from lintro.plugins.file_processor import AggregatedResult, FileProcessingResult 

47from lintro.plugins.protocol import LintroPlugin, ToolDefinition 

48from lintro.plugins.registry import ToolRegistry, register_tool 

49 

50# BaseToolPlugin is imported lazily to avoid circular imports 

51# Use: from lintro.plugins.base import BaseToolPlugin 

52 

53__all__ = [ 

54 "AggregatedResult", 

55 "FileProcessingResult", 

56 "LintroPlugin", 

57 "ToolDefinition", 

58 "ToolRegistry", 

59 "register_tool", 

60]