Skip to content

Commit 251278a

Browse files
committed
use strict version behavior
1 parent d6b1f5b commit 251278a

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

clang_tools/install.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:
2828
2929
:returns: The path to the detected tool (if found), otherwise `None`.
3030
"""
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))
3236
exe_name = (
3337
f"{tool_name}" + (f"-{ver_major}" if install_os != "windows" else "") + suffix
3438
)
@@ -39,21 +43,22 @@ def is_installed(tool_name: str, version: str) -> Optional[Path]:
3943
except (FileNotFoundError, subprocess.CalledProcessError):
4044
return None # tool is not installed
4145
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()
5146
print(
5247
f"Found a installed version of {tool_name}:",
5348
ver_num.groups(0)[0].decode(encoding="utf-8"),
54-
"at",
55-
str(path),
49+
end=" "
5650
)
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
5762
return path
5863

5964

0 commit comments

Comments
 (0)