11
11
12
12
13
13
def get_version_from_dependency (tool : str ) -> Optional [str ]:
14
+ """Get the version of a tool from the pyproject.toml dependencies."""
14
15
pyproject_path = Path (__file__ ).parent .parent / "pyproject.toml"
15
16
if not pyproject_path .exists ():
16
17
return None
@@ -108,6 +109,7 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
108
109
109
110
110
111
def _resolve_version (versions : List [str ], user_input : Optional [str ]) -> Optional [str ]:
112
+ """Resolve the version based on user input and available versions."""
111
113
if user_input is None :
112
114
return None
113
115
try :
@@ -131,6 +133,7 @@ def _resolve_version(versions: List[str], user_input: Optional[str]) -> Optional
131
133
132
134
133
135
def _get_runtime_version (tool : str ) -> Optional [str ]:
136
+ """Get the runtime version of a tool."""
134
137
try :
135
138
output = subprocess .check_output ([tool , "--version" ], text = True )
136
139
if tool == "clang-tidy" :
@@ -144,6 +147,7 @@ def _get_runtime_version(tool: str) -> Optional[str]:
144
147
145
148
146
149
def _install_tool (tool : str , version : str ) -> Optional [Path ]:
150
+ """Install a tool using pip."""
147
151
try :
148
152
subprocess .check_call (
149
153
[sys .executable , "-m" , "pip" , "install" , f"{ tool } =={ version } " ]
@@ -155,6 +159,7 @@ def _install_tool(tool: str, version: str) -> Optional[Path]:
155
159
156
160
157
161
def _resolve_install (tool : str , version : Optional [str ]) -> Optional [Path ]:
162
+ """Resolve the installation of a tool, checking for version and installing if necessary."""
158
163
user_version = _resolve_version (
159
164
CLANG_FORMAT_VERSIONS if tool == "clang-format" else CLANG_TIDY_VERSIONS ,
160
165
version ,
@@ -191,6 +196,7 @@ def is_installed(tool: str) -> Optional[Path]:
191
196
192
197
193
198
def ensure_installed (tool : str , version : Optional [str ] = None ) -> str :
199
+ """Ensure a tool is installed, resolving its version if necessary."""
194
200
LOG .info ("Ensuring %s is installed" , tool )
195
201
tool_path = _resolve_install (tool , version )
196
202
if tool_path :
0 commit comments