Coverage for lintro / tools / core / version_requirements.py: 70%

23 statements  

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

1"""Tool version requirements checking utilities.""" 

2 

3from __future__ import annotations 

4 

5from loguru import logger 

6 

7from lintro.tools.core.tool_registry import ToolRegistry 

8from lintro.tools.core.version_checking import ( 

9 get_install_hints, 

10 get_minimum_versions, 

11) 

12from lintro.tools.core.version_parsing import ( 

13 ToolVersionInfo, 

14 check_tool_version, 

15 compare_versions, 

16 extract_version_from_output, 

17 parse_version, 

18) 

19 

20__all__ = [ 

21 "ToolVersionInfo", 

22 "check_tool_version", 

23 "get_all_tool_versions", 

24 "compare_versions", 

25 "extract_version_from_output", 

26 "get_install_hints", 

27 "get_minimum_versions", 

28 "parse_version", 

29] 

30 

31 

32def get_all_tool_versions() -> dict[str, ToolVersionInfo]: 

33 """Get version information for all supported tools. 

34 

35 Uses the unified ToolRegistry (manifest.json) as the single source of truth 

36 for tool commands and version requirements. 

37 

38 Returns: 

39 dict[str, ToolVersionInfo]: Dictionary mapping tool names to version info. 

40 """ 

41 registry = ToolRegistry.load() 

42 results = {} 

43 minimum_versions = get_minimum_versions() 

44 install_hints = get_install_hints() 

45 

46 for tool in registry.all_tools(include_dev=True): 

47 if not tool.version_command: 

48 continue 

49 

50 # The manifest's version_command is the complete probe command; 

51 # never append an extra --version flag. 

52 try: 

53 results[tool.name] = check_tool_version( 

54 tool.name, 

55 list(tool.version_command), 

56 append_version=False, 

57 ) 

58 except (OSError, ValueError, RuntimeError) as e: 

59 logger.debug(f"Failed to check version for {tool.name}: {e}") 

60 normalized_key = tool.name.replace("-", "_") 

61 min_version = minimum_versions.get( 

62 tool.name, 

63 minimum_versions.get(normalized_key, "unknown"), 

64 ) 

65 install_hint = install_hints.get( 

66 tool.name, 

67 install_hints.get(normalized_key, f"Install {tool.name}"), 

68 ) 

69 results[tool.name] = ToolVersionInfo( 

70 name=tool.name, 

71 min_version=min_version, 

72 install_hint=install_hint, 

73 error_message=f"Failed to check version: {e}", 

74 ) 

75 

76 return results