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
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Abstract base for install-type strategy classes."""
3from __future__ import annotations
5from abc import ABC, abstractmethod
7from lintro.tools.core.install_strategies.environment import InstallEnvironment
10class InstallStrategy(ABC):
11 """Strategy for a single install type (pip, npm, binary, cargo, rustup).
13 Each subclass knows how to check prerequisites, generate install
14 commands, and generate upgrade commands for its ecosystem.
15 """
17 @abstractmethod
18 def install_type(self) -> str:
19 """Return the install_type string this strategy handles.
21 Returns:
22 Identifier such as ``"pip"`` or ``"npm"``.
23 """
24 ...
26 @abstractmethod
27 def is_available(self, env: InstallEnvironment) -> bool:
28 """Check if the required package manager is available.
30 Args:
31 env: The current install environment.
33 Returns:
34 True if this strategy can execute installs.
35 """
36 ...
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.
46 Args:
47 env: The current install environment.
48 tool_name: Canonical tool name (needed to check brew formula maps).
50 Returns:
51 A skip-reason string if prerequisites are NOT met, or None if OK.
52 """
53 ...
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.
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.
73 Returns:
74 Shell command string to install the tool.
75 """
76 ...
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.
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.
96 Returns:
97 Shell command string to upgrade the tool.
98 """
99 ...