Coverage for src/paperap/plugins/base.py: 95%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-12 23:40 -0400

1""" 

2---------------------------------------------------------------------------- 

3 

4 METADATA: 

5 

6 File: base.py 

7 Project: paperap 

8 Created: 2025-03-04 

9 Version: 0.0.5 

10 Author: Jess Mann 

11 Email: jess@jmann.me 

12 Copyright (c) 2025 Jess Mann 

13 

14---------------------------------------------------------------------------- 

15 

16 LAST MODIFIED: 

17 

18 2025-03-04 By Jess Mann 

19 

20""" 

21 

22from __future__ import annotations 

23 

24from abc import ABC, abstractmethod 

25from typing import TYPE_CHECKING, Any 

26 

27if TYPE_CHECKING: 

28 from paperap.client import PaperlessClient 

29 

30 

31class Plugin(ABC): 

32 """Base class for all plugins.""" 

33 

34 # Class attributes for plugin metadata 

35 name: str | None = None 

36 description: str = "No description provided" 

37 version: str = "0.0.1" 

38 client: PaperlessClient 

39 config: dict[str, Any] 

40 

41 def __init__(self, client: "PaperlessClient", **kwargs: Any) -> None: 

42 """ 

43 Initialize the plugin. 

44 

45 Args: 

46 client: The PaperlessClient instance. 

47 **kwargs: Plugin-specific configuration. 

48 

49 """ 

50 self.client = client 

51 self.config = kwargs 

52 self.setup() 

53 super().__init__() 

54 

55 @abstractmethod 

56 def setup(self): 

57 """Register signal handlers and perform other initialization tasks.""" 

58 

59 @abstractmethod 

60 def teardown(self): 

61 """Clean up resources when the plugin is disabled or the application exits.""" 

62 

63 @classmethod 

64 def get_config_schema(cls) -> dict[str, Any]: 

65 """ 

66 Get the configuration schema for this plugin. 

67 

68 Returns: 

69 A dictionary describing the expected configuration parameters. 

70 

71 """ 

72 return {}