14
14
from typing import Optional , cast
15
15
16
16
from . import release_tag , install_os , RESET_COLOR , suffix , YELLOW
17
- from .util import download_file , verify_sha512 , get_sha_checksum , parse_version
17
+ from .util import download_file , verify_sha512 , get_sha_checksum , Version
18
18
19
19
20
20
#: This pattern is designed to match only the major version number.
21
21
RE_PARSE_VERSION = re .compile (rb"version\s([\d\.]+)" , re .MULTILINE )
22
22
23
23
24
- def is_installed (tool_name : str , version : int ) -> Optional [Path ]:
24
+ def is_installed (tool_name : str , version : Version ) -> Optional [Path ]:
25
25
"""Detect if the specified tool is installed.
26
26
27
27
:param tool_name: The name of the specified tool.
@@ -30,7 +30,9 @@ def is_installed(tool_name: str, version: int) -> Optional[Path]:
30
30
:returns: The path to the detected tool (if found), otherwise `None`.
31
31
"""
32
32
exe_name = (
33
- f"{ tool_name } " + (f"-{ version } " if install_os != "windows" else "" ) + suffix
33
+ f"{ tool_name } "
34
+ + (f"-{ version .info [0 ]} " if install_os != "windows" else "" )
35
+ + suffix
34
36
)
35
37
try :
36
38
result = subprocess .run (
@@ -56,16 +58,16 @@ def is_installed(tool_name: str, version: int) -> Optional[Path]:
56
58
path = Path (exe_path ).resolve ()
57
59
print ("at" , str (path ))
58
60
ver_tuple = ver_match .split ("." )
59
- if ver_tuple is None or ver_tuple [0 ] != str (version ):
61
+ if ver_tuple is None or ver_tuple [0 ] != str (version . info [ 0 ] ):
60
62
return None # version is unknown or not the desired major release
61
63
return path
62
64
63
65
64
- def clang_tools_binary_url (tool : str , version : int , tag : str = release_tag ) -> str :
66
+ def clang_tools_binary_url (tool : str , version : str , tag : str = release_tag ) -> str :
65
67
"""Assemble the URL to the binary.
66
68
67
69
:param tool: The name of the tool to download.
68
- :param version: The major version of the tool to download.
70
+ :param version: The version of the tool to download.
69
71
:param tag: The release tag used in the base URL.
70
72
71
73
:returns: The URL used to download the specified tool.
@@ -79,12 +81,12 @@ def clang_tools_binary_url(tool: str, version: int, tag: str = release_tag) -> s
79
81
80
82
81
83
def install_tool (
82
- tool_name : str , version : int , directory : str , no_progress_bar : bool
84
+ tool_name : str , version : str , directory : str , no_progress_bar : bool
83
85
) -> bool :
84
86
"""An abstract function that can install either clang-tidy or clang-format.
85
87
86
88
:param tool_name: The name of the clang-tool to install.
87
- :param version: The major version of the tools to install.
89
+ :param version: The version of the tools to install.
88
90
:param directory: The installation directory.
89
91
:param no_progress_bar: A flag used to disable the downloads' progress bar.
90
92
@@ -154,7 +156,7 @@ def move_and_chmod_bin(old_bin_name: str, new_bin_name: str, install_dir: str) -
154
156
155
157
def create_sym_link (
156
158
tool_name : str ,
157
- version : int ,
159
+ version : str ,
158
160
install_dir : str ,
159
161
overwrite : bool = False ,
160
162
target : Optional [Path ] = None ,
@@ -163,7 +165,7 @@ def create_sym_link(
163
165
doesn't have the version number appended.
164
166
165
167
:param tool_name: The name of the clang-tool to symlink.
166
- :param version: The major version of the clang-tool to symlink.
168
+ :param version: The version of the clang-tool to symlink.
167
169
:param install_dir: The installation directory to create the symlink in.
168
170
:param overwrite: A flag to indicate if an existing symlink should be overwritten.
169
171
:param target: The target executable's path and name for which to create a symlink
@@ -212,11 +214,11 @@ def create_sym_link(
212
214
return False
213
215
214
216
215
- def uninstall_tool (tool_name : str , version : int , directory : str ):
217
+ def uninstall_tool (tool_name : str , version : str , directory : str ):
216
218
"""Remove a specified tool of a given version.
217
219
218
220
:param tool_name: The name of the clang tool to uninstall.
219
- :param version: The major version of the clang-tools to remove.
221
+ :param version: The version of the clang-tools to remove.
220
222
:param directory: The directory from which to remove the
221
223
installed clang-tools.
222
224
"""
@@ -241,17 +243,12 @@ def uninstall_clang_tools(version: str, directory: str):
241
243
"""
242
244
install_dir = install_dir_name (directory )
243
245
print (f"Uninstalling version { version } from { str (install_dir )} " )
244
- version_tuple = parse_version (version )
245
246
for tool in ("clang-format" , "clang-tidy" ):
246
- uninstall_tool (tool , version_tuple [ 0 ] , install_dir )
247
+ uninstall_tool (tool , version , install_dir )
247
248
248
249
249
250
def install_clang_tools (
250
- version : int ,
251
- tools : str ,
252
- directory : str ,
253
- overwrite : bool ,
254
- no_progress_bar : bool ,
251
+ version : Version , tools : str , directory : str , overwrite : bool , no_progress_bar : bool
255
252
) -> None :
256
253
"""Wraps functions used to individually install tools.
257
254
@@ -272,7 +269,7 @@ def install_clang_tools(
272
269
native_bin = is_installed (tool_name , version )
273
270
if native_bin is None : # (not already installed)
274
271
# `install_tool()` guarantees that the binary exists now
275
- install_tool (tool_name , version , install_dir , no_progress_bar )
272
+ install_tool (tool_name , version . string , install_dir , no_progress_bar )
276
273
create_sym_link ( # pragma: no cover
277
- tool_name , version , install_dir , overwrite , native_bin
274
+ tool_name , version . string , install_dir , overwrite , native_bin
278
275
)
0 commit comments