@@ -28,7 +28,11 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:
28
28
29
29
:returns: The path to the detected tool (if found), otherwise `None`.
30
30
"""
31
- ver_major = version .split ("." )[0 ]
31
+ version_tuple = version .split ("." )
32
+ ver_major = version_tuple [0 ]
33
+ if len (version_tuple ) < 3 :
34
+ # append minor and patch version numbers if not specified
35
+ version_tuple += (0 ,) * (3 - len (version_tuple ))
32
36
exe_name = (
33
37
f"{ tool_name } " + (f"-{ ver_major } " if install_os != "windows" else "" ) + suffix
34
38
)
@@ -39,21 +43,22 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:
39
43
except (FileNotFoundError , subprocess .CalledProcessError ):
40
44
return None # tool is not installed
41
45
ver_num = RE_PARSE_VERSION .search (result .stdout )
42
- if (
43
- ver_num is None
44
- or ver_num .groups (0 )[0 ].decode (encoding = "utf-8" ).split ("." )[0 ] != ver_major
45
- ):
46
- return None # version is unknown or not the desired major release
47
- path = shutil .which (exe_name ) # find the installed binary
48
- if path is None :
49
- return None # failed to locate the binary
50
- path = Path (path ).resolve ()
51
46
print (
52
47
f"Found a installed version of { tool_name } :" ,
53
48
ver_num .groups (0 )[0 ].decode (encoding = "utf-8" ),
54
- "at" ,
55
- str (path ),
49
+ end = " "
56
50
)
51
+ path = shutil .which (exe_name ) # find the installed binary
52
+ if path is None :
53
+ print () # print end-of-line
54
+ return None # failed to locate the binary
55
+ path = Path (path ).resolve ()
56
+ print ("at" , str (path ))
57
+ if (
58
+ ver_num is None
59
+ or ver_num .groups (0 )[0 ].decode (encoding = "utf-8" ).split ("." ) != version_tuple
60
+ ):
61
+ return None # version is unknown or not the desired major release
57
62
return path
58
63
59
64
0 commit comments