Coverage for lintro / tools / core / install_strategies / rustup_strategy.py: 95%

22 statements  

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

1"""Rustup install strategy.""" 

2 

3from __future__ import annotations 

4 

5from lintro.enums.install_context import PackageManager 

6from lintro.tools.core.install_strategies.base import InstallStrategy 

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

8from lintro.tools.core.install_strategies.registry import register_strategy 

9 

10 

11class RustupStrategy(InstallStrategy): 

12 """Install strategy for Rust toolchain components via rustup.""" 

13 

14 def install_type(self) -> str: 

15 """Return ``'rustup'``.""" 

16 return "rustup" 

17 

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

19 """Available if rustup is on PATH.""" 

20 return env.has(PackageManager.RUSTUP) 

21 

22 def check_prerequisites( 

23 self, 

24 env: InstallEnvironment, 

25 tool_name: str, 

26 ) -> str | None: 

27 """Return skip reason if rustup is not available. 

28 

29 Args: 

30 env: The current install environment. 

31 tool_name: Canonical tool name. 

32 

33 Returns: 

34 Skip reason or None. 

35 """ 

36 if not env.has(PackageManager.RUSTUP): 

37 return f"{tool_name}: rustup not available (install Rust first)" 

38 return None 

39 

40 def install_hint( 

41 self, 

42 _env: InstallEnvironment, 

43 _tool_name: str, 

44 _tool_version: str, 

45 _install_package: str | None, 

46 install_component: str | None, 

47 ) -> str: 

48 """Generate rustup install hint. 

49 

50 Args: 

51 _env: The current install environment (unused). 

52 _tool_name: Canonical tool name (unused). 

53 _tool_version: Expected version (unused). 

54 _install_package: Unused for rustup. 

55 install_component: Rustup component name (e.g., ``"clippy"``). 

56 

57 Returns: 

58 Shell command string. 

59 """ 

60 if install_component: 

61 import shlex 

62 

63 return f"rustup component add {shlex.quote(install_component)}" 

64 return "rustup toolchain install stable" 

65 

66 def upgrade_hint( 

67 self, 

68 _env: InstallEnvironment, 

69 _tool_name: str, 

70 _tool_version: str, 

71 _install_package: str | None, 

72 _install_component: str | None, 

73 ) -> str: 

74 """Generate rustup upgrade hint. 

75 

76 Args: 

77 _env: The current install environment (unused). 

78 _tool_name: Canonical tool name (unused). 

79 _tool_version: Expected version (unused). 

80 _install_package: Unused for rustup. 

81 _install_component: Unused for upgrade. 

82 

83 Returns: 

84 Shell command string. 

85 """ 

86 return "rustup update stable" 

87 

88 

89register_strategy(RustupStrategy())