Coverage for lintro / tools / core / install_strategies / base.py: 100%

14 statements  

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

1"""Abstract base for install-type strategy classes.""" 

2 

3from __future__ import annotations 

4 

5from abc import ABC, abstractmethod 

6 

7from lintro.tools.core.install_strategies.environment import InstallEnvironment 

8 

9 

10class InstallStrategy(ABC): 

11 """Strategy for a single install type (pip, npm, binary, cargo, rustup). 

12 

13 Each subclass knows how to check prerequisites, generate install 

14 commands, and generate upgrade commands for its ecosystem. 

15 """ 

16 

17 @abstractmethod 

18 def install_type(self) -> str: 

19 """Return the install_type string this strategy handles. 

20 

21 Returns: 

22 Identifier such as ``"pip"`` or ``"npm"``. 

23 """ 

24 ... 

25 

26 @abstractmethod 

27 def is_available(self, env: InstallEnvironment) -> bool: 

28 """Check if the required package manager is available. 

29 

30 Args: 

31 env: The current install environment. 

32 

33 Returns: 

34 True if this strategy can execute installs. 

35 """ 

36 ... 

37 

38 @abstractmethod 

39 def check_prerequisites( 

40 self, 

41 env: InstallEnvironment, 

42 tool_name: str, 

43 ) -> str | None: 

44 """Check if prerequisites for installing via this strategy are met. 

45 

46 Args: 

47 env: The current install environment. 

48 tool_name: Canonical tool name (needed to check brew formula maps). 

49 

50 Returns: 

51 A skip-reason string if prerequisites are NOT met, or None if OK. 

52 """ 

53 ... 

54 

55 @abstractmethod 

56 def install_hint( 

57 self, 

58 env: InstallEnvironment, 

59 tool_name: str, 

60 tool_version: str, 

61 install_package: str | None, 

62 install_component: str | None, 

63 ) -> str: 

64 """Generate a context-aware install command string. 

65 

66 Args: 

67 env: The current install environment. 

68 tool_name: Canonical tool name. 

69 tool_version: Expected version. 

70 install_package: Package name override. 

71 install_component: Rustup component name. 

72 

73 Returns: 

74 Shell command string to install the tool. 

75 """ 

76 ... 

77 

78 @abstractmethod 

79 def upgrade_hint( 

80 self, 

81 env: InstallEnvironment, 

82 tool_name: str, 

83 tool_version: str, 

84 install_package: str | None, 

85 install_component: str | None, 

86 ) -> str: 

87 """Generate a context-aware upgrade command string. 

88 

89 Args: 

90 env: The current install environment. 

91 tool_name: Canonical tool name. 

92 tool_version: Expected version. 

93 install_package: Package name override. 

94 install_component: Rustup component name. 

95 

96 Returns: 

97 Shell command string to upgrade the tool. 

98 """ 

99 ...